Reputation: 1993
So, I'm trying to capture this big string in Python but it is failing me. The regex I wrote works fine in regexr: http://regexr.com/3cmdc
But trying to using it in Python to capture the text returns None. This is the code:
pattern = "var initialData = (.*?);\\n"
match = re.search(pattern, source).group(1)
What am I missing ?
Upvotes: 0
Views: 293
Reputation: 189
Use pythons raw string notation:
pattern = r"var initialData = (.*?);\\n"
match = re.search(pattern, source).group(1)
Upvotes: 1
Reputation: 473813
You need to set the appropriate flags:
re.search(pattern, source, re.MULTILINE | re.DOTALL).group(1)
Upvotes: 1