ID EN
Regular Expression

X

Python 3.11

This flag allows you to write regular expressions that look nicer and are more readable by allowing you to visually separate logical sections of the pattern and add comments. Whitespace within the pattern is ignored, except when in a character class, or when preceded by an unescaped backslash, or within tokens like *?, (?: or (?P. For example, (? : and * ? are not allowed. When a line contains a that is not in a character class and is not preceded by an unescaped backslash, all characters from the leftmost such through the end of the line are ignored.

Syntax

PYTHON
re.X

Examples

Example 1
PYTHON
a = re.compile(r"""\d +   the integral part
                   \.     the decimal point
                   \d *   some fractional digits""", re.X)
b = re.compile(r"\d+\.\d*")