Skip to main content

Groups and Capturing

Advanced Group Techniques

0:00
LearnStep 1/3

Inline Flags and Comments

Inline Flags and Comments

While standard re.compile() flags like re.IGNORECASE are powerful, sometimes you need to embed these instructions directly into the pattern string itself.

Common Inline Flags

  • (?i): Ignore Case. Makes the pattern case-insensitive.
  • (?m): Multiline. Changes the behavior of ^ and $ to match the start and end of each line.
  • (?s): Dotall. Makes the . (dot) metacharacter match all characters, including newlines.
  • (?x): Verbose. Ignores whitespace and allows comments within the pattern.

Using Inline Flags

python

Inline Comments

You can add comments directly inside a regex using the (?#...) syntax.

python