I have a large collection of regular expressions, and I apply them all using a few flags with something like:
re.search(aRegex,aString,flags=re.IGNORECASE | re.UNICODE)
unfortunately, there are one or two for which I don't want to ignore case. Python provides a handy way to set flags from within a regular expression (eg: r'(?iu)...'
sets the re.IGNORECASE
and re.UNICODE
flags).
Is there a way that I can unset flags from within an expression? Perhaps somerthing like:
r'(?i-)...'
or
r'(?I)...'
to force case sensitivity. (btw: neither of those work..)
There is no way to unset a flag once you set it (in the regex or in a function) in the Python 2.x re
module. (There is also no way to set a flag for a portion of the regex either).
Consider using regex
package if you need such feature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With