Test and debug Python regular expressions online with the Qodex Python Regex Tester. Instantly highlight matches and refine patterns used for email validation, password checks, phone number validation, and more. Use data from the Email Generator or UUID Generator, and compare behavior with the Java or JavaScript Regex Testers.
[A-Z]
: uppercase letters[a-z]
: lowercase letters[0-9]
: digits\.
: a literal dot+
: one or more of the preceding*
: zero or more of the preceding?
: optional (zero or one)^
: start of string$
: end of string
Test your APIs today!
Write in plain English — Qodex turns it into secure, ready-to-run tests.
Regular Expression - Documentation
What is Python Regex?
Python uses the built-in re module to support regular expressions. Regex allows you to match, extract, and transform text using patterns. It’s widely used in:
Data validation (e.g., email, password, phone numbers)
Text processing and cleanup
Web scraping and log analysis
Extracting patterns from strings
Core Components of Python RegEx
Real-Time Matching – Immediate pattern matching and highlight as you type.
Supports Python re Syntax – Works exactly like Python’s regex engine.
Capturing Groups Displayed – Shows capture groups and matches.
Beginner-Friendly – Just paste your regex and test string—no coding required.
Integrates with Test Tools – Try with Address Generator, Password Generator, or MAC Address Generator.
Metacharacters
.
- Matches any character except newline(\n)
.Example:
a.b
matchesacb
,a9b
, etc., but notab
.^
- Matches the start of a string.Example:
^Hello
matches “Hello world
” but not “Say Hello
”.$
- Matches the end of a string or just before the newline at the end.Example:
world$
matches “Hello world
” but not “world peace
”.|
- Acts as a logical OR operator.Example:
cat|dog
matches either “cat
” or “dog
”.
Character Classes
[abc]
- Matches any one ofa
,b
, orc
.Example:
gr[ae]y
matches both “gray
” and “grey
”.[^abc]
- Negates the set. Matches any character excepta
,b
, orc
.Example:
[^0-9]
matches any non-digit.[a-zA-Z]
- Matches any alphabet character.Example:
[A-Z]
matches uppercase letters only.
Predefined Character Classes
\d
: Matches any digit character; equivalent to[0-9]
.\D
: Matches any non-digit character.\s
: Matches any whitespace character: space, tab, newline, etc.\S
: Matches any non-whitespace character.\w
: Matches any word character:[a-zA-Z0-9_]
.\W
: Matches any character not considered a word character.
Quantifiers
*
- Matches 0 or more repetitions of the preceding pattern.Example:
ab*
matches “a
”, “ab
”, “abb
”, “abbb
”…+
- Matches 1 or more occurrences.Example:
ab+
matches “ab
”, “abb
”, “abbb
”… but not “a
”.?
- Matches 0 or 1 occurrence, making it optional.Example:
ab?
matches “a
” or “ab
”.{n}
- Exactlyn
occurrences.Example:
a{3}
matches “aaa
”.{n,}
- At leastn
occurrences.Example:
a{2,}
matches “aa
”, “aaa
”, “aaaa
”…{n,m}
- Betweenn
andm
occurrences.Example:
a{2,4}
matches “aa
”, “aaa
”, or “aaaa
”.
Groups and Lookarounds
(
abc
) : Capturing group that matches “abc
” and stores it.Example:
(ha)+
matches “ha
”, “hahaha
”, etc.(
?:abc
) : Non-capturing group; groups without saving.Useful when applying quantifiers or alternations without backreferences.
(
?=abc
) : Positive lookahead; matches if abc follows.Example:
\d(?=px)
matches a digit followed by “px
”.(
?!abc
) : Negative lookahead; matches if abc does not follow.Example:
\d(?!px)
matches digits not followed by “px
”.(
?<=abc
) : Positive lookbehind; matches if preceded by abc.Example:
(?<=@)\w+
matches text after “@” in an email.(
?<!abc
) : Negative lookbehind; matches if not preceded by abc.
Anchors and Boundaries
\b
: Word boundary (between\w
and\W
).Example:
\bcat\b
matches “cat
” in “the cat sat
” but not “catering
”.\B
: Non-word boundary.Example:
\Bend
matches “bend
” but not “end
”.\A
: Matches the start of the string (unlike^
, it doesn’t change withre.MULTILINE
).\Z
: Matches the end of the string or before the newline at the end.\z
: Matches the absolute end of the string (rare in Python, often replaced with\Z
).
Flags
You can pass flags to functions like re.search() or use them inline with (?i), (?m), etc.
re.IGNORECASE / re.I
: Case-insensitive matchingre.MULTILINE / re.M
:^
and$
match line start/endre.DOTALL / re.S
: . matches newlinesre.VERBOSE / re.X
: Allow whitespace and comments in the regexre.ASCII / re.A
: Restrict\w
,\d
, etc., to ASCII (not Unicode)
Python Regular Expressions Examples
Example 1: Email Validation
Try the Email RegEx Python Validator and Email Generator to test this pattern interactively.
Example 2: Password Strength Check
Use the Password RegEx Python Validator or generate test data with our Password Generator
Example 3: Extracting Words from a String
Useful for NLP, logs, or data pipelines
How It Works
Enter your regex pattern and sample test string.
View instant matches and capture groups below.
Copy, edit, and refine your pattern until it’s perfect.
Use test data from other tools to simulate real-world cases.
Pro Tips for Writing Effective RegEx in Python
Compile regex using re.compile() for better performance in loops.
Use named groups ((?P<name>...)) for cleaner, readable code.
Use re.VERBOSE for large regex, allowing comments and spacing.
Leverage
re.findall()
to return all matches as a list.Avoid regex for deeply nested or structured data—use parsers instead.
Use Qodex’s Python Regex Tester to experiment with edge cases and live data.
Try generating test data with our Email Generator, UUID Generator, or Password Generator.
Combine regex with list comprehensions for powerful one-liners.
When debugging, test sections of complex patterns separately before joining them.
Tools for Enhanced RegEx Workflows
Other Regex Validators
Generators for Testing
Encoders & Decoders
Explore More on Qodex
Use Qodex to test and validate patterns in multiple languages