Regex Tester
Test regular expressions online with live match highlighting, capture groups, a replace preview and a plain-English explanation of the pattern. Runs in your browser.
Pattern library
Loads the pattern, flags and an exampleValidate
Extract
Clean up
Code & data
Result
Enter a pattern and some text: every match and capture group will be listed here.
Enter a valid pattern to see it explained token by token.
In other languages
Why test a regex before you use it?
A regular expression that looks right can still match too much, too little or nothing at all, and the mistake often only shows up on real data. Testing on a sample first shows exactly what each part of the pattern grabs. This tester highlights every match, lists each capture group with its position, previews replacements and explains the pattern in plain English, so you can see why it matches. It uses your browser's JavaScript engine, flags syntax that behaves differently in Python, PHP, Java, .NET and Go, and keeps everything on your device.
How it works
- Type a pattern between the slashes, or pick one from the Library. Pasting a whole literal such as
/\d+/gifills in the pattern and switches on its flags. - Turn on flags: g for every match, i to ignore case, m for line-by-line ^ and $, s so . matches line breaks.
- Paste your text. Matches are highlighted as you type and listed with their capture groups in the Matches tab; copy them as a list or CSV.
- Switch to Replace to preview a substitution, read the Explain tab to check the logic, and take the pattern into your code from the Code tab.
Regex cheat sheet
The syntax you'll use in nine patterns out of ten. Every line works in this tester; click Explain on your own pattern for a breakdown.
| Syntax | Meaning |
|---|---|
| . | Any character except a line break (any at all with the s flag) |
| \d \w \s | A digit, a word character (A–Z, a–z, 0–9, _), whitespace |
| \D \W \S | Anything except a digit, word character, whitespace |
| [abc] [a-z] | One character from a set or range |
| [^abc] | One character not in the set |
| ^ $ | Start and end of the text (of each line with m) |
| \b \B | A word boundary; not a word boundary |
| * + ? | 0 or more, 1 or more, 0 or 1 of the previous item |
| {3} {2,} {2,5} | Exactly 3, 2 or more, 2 to 5 times |
| *? +? ?? | Lazy versions: as few as possible |
| (abc) | Capturing group, numbered from 1 |
| (?<name>abc) | Named capturing group |
| (?:abc) | Group without capturing |
| a|b | Either a or b |
| \1 \k<name> | The same text a group matched earlier |
| (?=x) (?!x) | Followed by x; not followed by x |
| (?<=x) (?<!x) | Preceded by x; not preceded by x |
| \p{L} \p{N} | Any letter or number in any script (u flag) |
| \. \* \\ | A literal dot, asterisk, backslash |
Worked example: pulling dates out of text
Say a changelog mentions dates like 2024-03-15 and you want them as day/month/year. Start with the simplest thing that could work, \d{4}-\d{2}-\d{2}, and test it: it also matches 2024-13-45, because \d accepts any digit. Tighten the month to (0[1-9]|1[0-2]) and the day to (0[1-9]|[12]\d|3[01]), then name the parts:
(?<year>\d{4})-(?<month>0[1-9]|1[0-2])-(?<day>0[1-9]|[12]\d|3[01])In Replace mode, $<day>/$<month>/$<year> rewrites each date, and the preview highlights exactly what changed. The Explain tab confirms that each group means what you intended, and the Code tab writes the Python version with (?P<year>…) groups and \g<day> references. The pattern still accepts 2024-02-31; checking real calendar dates is a job for code, not regex. This exact pattern is in the library as “ISO date, named groups”.
Replacement references
In Replace mode the replacement text understands these references. The last column shows how Python's re.sub writes the same thing.
| JavaScript | Inserts | Python |
|---|---|---|
| $1 … $99 | The text of a numbered group | \1 or \g<1> |
| $<name> | The text of a named group | \g<name> |
| $& | The whole match | \g<0> |
| $` | Everything before the match | (use a function) |
| $' | Everything after the match | (use a function) |
| $$ | A literal $ | $ |
Regex flavors: JavaScript vs Python, PHP, Java, .NET and Go
Regex engines share a core syntax but differ at the edges, and those edges are where patterns copied between languages break. This tester runs JavaScript's engine; the table shows what changes elsewhere. PHP's preg functions use the PCRE2 library, and Go uses RE2, which trades lookarounds and backreferences for a guarantee of linear-time matching.
| Feature | JavaScript | Python re | PHP (PCRE2) | Java | .NET | Go (RE2) |
|---|---|---|---|---|---|---|
| Named group | (?<n>…) | (?P<n>…) | Both | (?<n>…) | (?<n>…) or (?'n'…) | (?P<n>…); (?<n>…) from 1.22 |
| Lookahead | Yes | Yes | Yes | Yes | Yes | No |
| Lookbehind | Any length | Fixed length | Fixed or bounded | Bounded | Any length | No |
| Backreferences | Yes | Yes | Yes | Yes | Yes | No |
| Atomic groups, possessive | No | Yes (3.11+) | Yes | Yes | Atomic only | No |
| Start / end of text | ^ $ without m | \A \Z | \A \z | \A \z | \A \z | \A \z |
| Inline flags (?i) | Only (?i:…) groups, since 2025 | Yes | Yes | Yes | Yes | Yes |
| \p{L} Unicode classes | With the u flag | No (regex module) | Yes | Yes | Yes | Yes |
| \d matches non-ASCII digits | No | Yes | No | No | Yes | No |
One difference catches almost everyone: in Python, PHP and Java, $ also matches just before a line break at the very end of the text, so ^\d+$ accepts "123\n" there but not in JavaScript. When a pattern guards input validation, use \z (or \Z in Python) in those languages.
Common regex mistakes
- Unescaped dots.
example.comalso matchesexampleXcom. Writeexample\.com. - Greedy
.*running too far. On a line with two quoted strings,".*"matches from the first quote to the last. Use".*?"or"[^"]*". - Missing anchors in validation.
\d{5}finds five digits inside1234567. To check that the whole input is five digits, use^\d{5}$. [A-z]as “any letter”. The range runs through the ASCII table, so it also includes[ \ ] ^ _and the backtick. Use[A-Za-z].- Forgetting the g flag. Without it, JavaScript's
replacechanges only the first match andmatchAllthrows an error. - Nested quantifiers.
(\w+)*and similar patterns can backtrack for minutes on text that doesn't match. This page stops any pattern after one second and tells you why. - Parsing HTML or JSON with regex. Fine for a quick search, but nesting defeats it. Use a parser, or the JSON formatter for JSON.
After a replace, the text diff tool shows the before and after side by side. For jobs that don't need a pattern at all, remove duplicate lines and the case converter are quicker, and the UUID pattern in the library matches the IDs made by the UUID generator.
Frequently asked questions
How do I test a regular expression online?
Type the pattern between the slashes, switch on any flags, and paste the text you want to search into the test string box. Matches are highlighted as you type, the match table lists each match with its position and capture groups, and the Explain tab describes the pattern piece by piece. Switch to Replace to preview a substitution before you run it in your code.
Which regex flavor does this tester use?
Matching runs on your browser's own JavaScript (ECMAScript) regex engine, so results are exactly what JavaScript and Node.js will do. Most everyday syntax works the same in Python, PHP, Java, .NET and Go. Where your pattern uses something that behaves differently in another language, such as lookbehind, named groups or $, the Explain tab lists the difference, and the Code tab converts the pattern for that language.
What do the regex flags g, i, m, s, u and y mean?
g (global) finds every match instead of stopping at the first. i ignores case. m (multiline) makes ^ and $ match at the start and end of each line. s (dotAll) lets . match line breaks. u (unicode) reads the pattern and text as Unicode code points and enables \p{…} property escapes. y (sticky) only matches at the exact position where the last match ended.
How do I match a literal dot, bracket or other special character?
Put a backslash in front of it. The characters with special meaning are . * + ? ^ $ { } ( ) | [ ] \ and, inside a JavaScript literal, /. So \. matches a dot, \( an opening parenthesis and \\ a backslash. Inside square brackets most of them lose their meaning: [.] also matches a literal dot.
What is the difference between greedy and lazy quantifiers?
A greedy quantifier (*, +, ?, {n,m}) takes as much text as it can and gives some back only if the rest of the pattern fails. Adding ? makes it lazy, taking as little as possible. On <b>bold</b>, the greedy <.+> matches the whole string, while the lazy <.+?> matches <b> and </b> separately.
How do I use capture groups in a replacement?
In JavaScript replacements, $1 to $99 insert numbered groups, $<name> a named group, $& the whole match, $` the text before it, $' the text after it, and $$ a literal dollar sign. For example, (\d{4})-(\d{2})-(\d{2}) replaced with $3/$2/$1 turns 2024-03-15 into 15/03/2024. Python writes the same references as \1 or \g<name>; the Code tab converts them.
Why does my regex work in Python or PHP but not in JavaScript?
Usually because of syntax JavaScript doesn't share. Python names groups (?P<name>…); JavaScript uses (?<name>…). \A, \Z and \z don't exist in JavaScript and silently match the letters A and Z; use ^ and $ instead. JavaScript also lacks possessive quantifiers (a++), atomic groups (?>…), inline flags such as (?i) at the start of a pattern, and recursion. This tester flags each of these with a specific message.
How do I match across multiple lines?
Two different things are called multiline. To let . match line breaks, turn on the s flag or use [\s\S] instead of the dot. To make ^ and $ match at the start and end of every line rather than the whole text, turn on the m flag. Windows text has \r\n line endings, so a pattern for one line break should usually be \r?\n.
What is catastrophic backtracking?
Patterns with nested or overlapping quantifiers, such as (a+)+$ or (\w+\s?)*$, can take exponentially longer as the text grows when no match exists, because the engine tries every way of splitting the text between the quantifiers. This tester runs the pattern in a background worker and stops it after one second, so the page never freezes. Fix such a pattern by making the alternatives mutually exclusive or removing the nested quantifier.
Can a regex validate email addresses perfectly?
No practical regex can. The full address syntax in RFC 5322 allows quoted strings, comments and IP literals that no one uses in real sign-up forms. Use a simple shape check like the one in the pattern library to catch typos, then confirm the address by sending an email to it.
How do I share a regex with someone?
Press Share link. The pattern, flags, replacement and up to 3,000 characters of test text are written into the part of the link after the # sign, which browsers never send to a server, and the person you send it to sees the same test. The link contains your test text, so leave out anything private.
Is my text uploaded anywhere?
No. Matching, replacing and explaining all happen in your browser. Your last pattern, flags and test text are kept in this browser's local storage so they are still there when you come back; Clear removes them.
Related tools
More free, private, browser-based utilities — no upload, no sign-up.