Regex tester
Find phone numbers, emails or dates in any text and fix them in one go.
PrivateNo uploadsRuns in your browserMatches
Cheat sheet
- .
- any char
- \d \w \s
- digit, word, space
- \b
- word boundary
- ^ $
- start, end
- * + ?
- 0+, 1+, 0 or 1
- {n,m}
- n to m times
- [abc] [^abc]
- set, negated set
- (a|b)
- group, alternation
- (?<name>…)
- named group
- (?:…)
- non-capturing
- (?=…) (?!…)
- lookahead
- (?<=…) (?<!…)
- lookbehind
- \1 $1
- backreference, replace

For the tricky search
Find just what you need.
The puzzle. Harish needs every phone number in a list.
BeforeTrial and error in the code
With sdevSee every match as you type

It matches
Each match lights up as he types.

Coffee earned
Puzzle solved, time for a break.
How to test a regular expression
Write the pattern
Type it between the slashes, without delimiters. Toggle flags with the buttons: g finds every match, i ignores case, m makes ^ and $ work per line, s lets . match newlines. Or pick one from Common patterns to start from.
Add test text
Paste into Test string, press Open to load a text file, or use Sample. Matches are highlighted as you type and listed in the table with their position and capture groups.
Replace if needed
Press Replace to show the replacement field. Use $1 for numbered groups, $<name> for named groups and $& for the whole match. The result appears in its own pane with a Copy button.
Good to know
- Patterns use JavaScript syntax: named groups (?<year>\d{4}), lookbehind (?<=...) and Unicode property classes with the u flag. PCRE-only features such as possessive quantifiers and atomic groups are not available.
- The g flag is always applied when listing matches, so you see them all. Replace honours your flags, so leave g off to replace only the first occurrence.
- A pattern that never finishes, usually nested quantifiers such as (a+)+ on a long string, is stopped after 3 seconds and the worker is restarted. Tighten the pattern rather than waiting.
- Ctrl+C (Cmd+C on Mac) with nothing selected copies every match, one per line, or the replaced text when Replace is open.
- Text files up to 512 KB load into the test string. Highlighting is skipped above 200,000 characters, the count includes every match, details are kept for the first 5,000 and the table lists the first 200.
- Matching runs in a web worker in your browser. Nothing is uploaded. The Cheat sheet at the bottom lists the tokens people forget.
Where people use it
Check a form rule
Test an email, phone or PIN code pattern before you put it in your app.
Pull data out of text
Use groups to grab dates, amounts or ids from logs and reports.
Clean a big file
Try a replace with live preview, then copy the result.
Learn regex
Start from a common pattern and change it bit by bit while matches light up.
Replace many words without regex
Just want to swap a list of words? The find and replace page is simpler.
Find and replace many words at once
Why this one
It is safe on long text: a pattern that never finishes is stopped after a few seconds instead of freezing the page.
- Matches light up as you type.
- Shows groups and a replace preview.
- A library of common patterns to start from.
- Runs in your browser and stops runaway patterns.
What you can change
- Flags such as g, i and m
- Replace text
- Common patterns list
People find this page by searching
- regex tester
- regex online
- regular expression tester
- regex for email validation
- regex for phone number
- javascript regex tester
- regex replace online
- regex cheat sheet
Cite this tool
- APA
sdev.in. (n.d.). Regex tester online [Web tool]. https://www.sdev.in/tools/regex-tester
- MLA
"Regex tester online." sdev.in, https://www.sdev.in/tools/regex-tester.
- Chicago
sdev.in. "Regex tester online." https://www.sdev.in/tools/regex-tester.
- BibTeX
@misc{sdev-regex-tester, title = {Regex tester online}, author = {{sdev.in}}, howpublished = {\url{https://www.sdev.in/tools/regex-tester}}, note = {Web tool} }
Questions people ask
Why does Replace only change the first occurrence?
The g flag is off. The match list always shows every match, but Replace follows your flags exactly, the same as String.replace in JavaScript. Turn on g to replace them all.
How do I use capture groups in the replacement?
Wrap the part you need in parentheses and refer to it as $1, $2 and so on, or name it with (?<name>...) and use $<name>. $& inserts the whole match. The Groups column in the match table shows what each group captured.
Why does ^ or $ not match each line?
By default they match only the start and end of the whole text. Turn on the m flag so they match at every line break. For . to cross line breaks as well, turn on s.
Why do I get a timeout?
Some patterns backtrack exponentially on inputs that almost match, for example (\w+\s?)+$ on a long line. The tester stops them after 3 seconds. Make the pattern more specific, use non-greedy quantifiers or anchor it.
Will the pattern work in Python, Java or Go?
Mostly. The core syntax is shared, but details differ: named groups are (?P<name>) in Python, Go's RE2 has no lookaround or backreferences, and flag letters vary. Test in the target language before shipping.