Today Pythong does not allow changing regex options which happen to be not at the start of the string. For instance:
import re
s = "I luv Python and CPython"
matches = re.finditer(r"\b(?i)[A-Z](?-i)[a-z]+\b", s)
As you can see, the first character in the bounded string can be of any case (?i)
, but starting from the second character, all of them must be in lower-case since (?-i)
cancels insensitiveness of the first option. In .NET it gives expected result:
'luv'
'Python'
'and'
CPython
was excluded because second character P
is upper-case, when it must be lower-case.
Is it possible to realize same in Python?