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 ?
match = re.search(pattern, source, re.S).group(1)
, but if your string is very large, you might have an issue related to the lazy matching stack "overflow".r'var initialData = ([^;]*(?:;(?!\\n)[^;]*)*)'
pattern if your\n
contains a literal\
. Else, if\n
is a normal linebreak, I'd adviser'var initialData = ([^;]*(?:;(?!\n)[^;]*)*)'
var initialData = (.*?);
orvar initialData = (.*?);\r?\n
and get on with life. Or evenvar initialData = ([\S\s]*?);