pythonregex

python regex: Is there a flag value for NOT ignorecase?


When doing regex matching, we do

re.match(regex, text)

To ignore case we could do

re.match(regex, text, re.IGNORECASE)

Is there a flag/value for NOT ignore case?

Would like to keep my code a bit more cleaner by not doing

if XXX:
    re.match(regex, text, re.IGNORECASE)
else:
    re.match(regex, text)

It would be great if I could do sth like

re.match(regex, text, re.IGNORECASE if XXX else re.NOTIGNORE)

Solution

  • No. This is not possible for Python/re library.

    The flag is a int value. You can try with different values. None would work. See details in https://docs.python.org/2/library/re.html#regular-expression-objects