I have this regex code in python :
if re.search(r'\{\\fad|fade\(\d{1,4},\d{1,4}\)\}', text): print(re.search(r'\{\\fad|fade\((\d{1,4}),(\d{1,4})\)\}', text).groups())
text is {\fad(200,200)}Épisode 101 : {\i1}The Ghost{\i0}\Nv. 1.03 and read from a file (don’t know if that helps).
This returns the following:
(None, None)
When I change the regex in the print to r'\{\\fad\((\d{1,4}),(\d{1,4})\)\}', it returns the correct values:
(200, 200)
Can anyone see why the conditional fad|fade matches the regex in the re.search but doesn’t return the correct values of the groups in the print?
Thanks.
Put extra parens around the choice:
re.search(r'{(?:\\fad|fade)\((\d{1,4}),(\d{1,4})\)}', text).groups()Also, escaping
{}braces isn’t necessary, it just needlessly clutters your regexp.