Python regex module: what flag is behind a number representation in Regex instance?

Viewed 32

Which flags are used by default, i.e. what is behind the number 8224? Is there a list of number representations of flags?

>>> import regex
>>> compiled_pattern = regex.compile("/d+")
>>> compiled_pattern.flags
8224
1 Answers

It's a bitfield, i.e. each bit represents the presence of a flag.

>>> re.compile("/d+", re.IGNORECASE).flags
34

>>> re.RegexFlag(34)
re.IGNORECASE|re.UNICODE

>>> int(re.IGNORECASE) | int(re.UNICODE)
34

>>> {f: int(f) for f in re.RegexFlag}
{re.ASCII: 256, re.IGNORECASE: 2, re.LOCALE: 4, re.UNICODE: 32, re.MULTILINE: 8, re.DOTALL: 16, re.VERBOSE: 64, re.TEMPLATE: 1, re.DEBUG: 128}
Related