SyntaxStudy
Sign Up
Python Intermediate 3 min read

Regex Flags

Regex Flags

Flags modify matching behavior. Common ones: re.IGNORECASE, re.MULTILINE, re.DOTALL, re.VERBOSE.

Example
import re

text = "Hello
World"
# re.DOTALL makes . match newlines too
match = re.search(r"Hello.World", text, re.DOTALL)
print(match.group())  # Hello
World

# re.IGNORECASE
print(re.findall(r"hello", text, re.I))  # ["Hello"]
Pro Tip

Use re.VERBOSE to write multi-line, commented patterns for complex regex.