In Python's regex: why does regex1 complain about fixed-width look-behinds if regex2 does not? Is ^ (start marker) more than 1 character?
Regex1
(?<=^|b)[0-9]
Regex2
(?<=a|b)[0-9]
Reproduceable in https://regex101.com/r/L5J47R/2
In Python's regex: why does regex1 complain about fixed-width look-behinds if regex2 does not? Is ^ (start marker) more than 1 character?
Regex1
(?<=^|b)[0-9]
Regex2
(?<=a|b)[0-9]
Reproduceable in https://regex101.com/r/L5J47R/2
Reason why first regex is nor working in Python because ^ is a zero width match and Python regex engine doesn't support alternation of zero with and non-zero alternations in the lookbehind assertion.
This is however supported in other engines such as Java, PHP, Perl, C# etc.
To solve this problem, you can use this regex:
(?:^|(?<=b))[0-9]
^is zero width match and Python regex engine doesn't support alternation of zero with and non-zero alternations in lookbehind.