Python 3.6+reterm
re.RegexFlag
flags
An enumeration of regex flags (IGNORECASE, MULTILINE, DOTALL, …).
Syntax
re.RegexFlag
RegexFlag is an enum.IntFlag, so the flags are plain bit masks: re.I | re.M produces another RegexFlag whose value is 10, and combining with | is the usual way to pass several flags in the flags argument; the other route is inline flags inside the pattern itself, such as (?im). You rarely spell out re.RegexFlag yourself — it shows up in type hints and reprs, while calls use the short re.I, re.M, re.S.
Examples
import re
print(re.IGNORECASE.name) # → IGNORECASE
print(bool(re.match('abc', 'ABC', re.IGNORECASE))) # → True
print(re.IGNORECASE.value) # → 2
flags = re.IGNORECASE | re.MULTILINE
print(re.findall('^b', 'a\nB', flags)) # → ['B']
See also
Open in the full glossarydocs.python.orgReport an inaccuracy