This code returns None, what am I doing wrong? I'm assuming it has something to do with special characters
test=re.search('The Girl Who Played with Fire (Millennium #2)', 'The Girl Who Played with Fire (Millennium #2)',re.IGNORECASE)
print(test)
This code returns None, what am I doing wrong? I'm assuming it has something to do with special characters
test=re.search('The Girl Who Played with Fire (Millennium #2)', 'The Girl Who Played with Fire (Millennium #2)',re.IGNORECASE)
print(test)
The parenthesis are being treated as grouping operators when the string is used as a pattern.
Try this instead:
test=re.search(
'The Girl Who Played with Fire [(]Millennium #2[)]',
'The Girl Who Played with Fire (Millennium #2)',
re.IGNORECASE
)
You have to escape (
and )
in Regex:
test=re.search(
'The Girl Who Played with Fire \(Millennium #2\)', # <- NOTICE
'The Girl Who Played with Fire (Millennium #2)',
re.IGNORECASE)
print(test)