Regex Tester
Test a JavaScript regular expression against your text: every match is highlighted, capture groups are listed, and each part of the pattern is explained in plain English.
Runs in your browser; your pattern and text are never uploaded.
Enter a pattern and some text to see the matches, their positions and capture groups.
Related Developer Tools
This regex tester checks a regular expression against your text as you type. Matches are highlighted in the text and listed with their positions and capture groups, the Replace tab previews a find-and-replace, and the Explain tab breaks the pattern into parts with a plain-English description of each. It uses the JavaScript regex engine built into your browser, so what you see is what String.prototype.match, matchAll and replace will do in your code. Open a log or text file, or load one from a URL, to test against real data.
Regex Cheat Sheet
| Syntax | Matches |
|---|---|
. | Any character except a line break (any character at all with the s flag) |
\d \w \s | A digit; a letter, digit or underscore; whitespace. Capitals (\D \W \S) mean the opposite |
[abc] [a-z] [^0-9] | One of a, b or c; one lowercase letter; one character that is not a digit |
^ $ | Start and end of the text (of each line with the m flag) |
\b | A word boundary: between a word character and a non-word character |
* + ? | Zero or more, one or more, zero or one of the previous item |
{3} {2,} {2,5} | Exactly 3, at least 2, between 2 and 5 times |
*? +? {2,5}? | Lazy versions: match as little as possible |
(…) (?<name>…) | A capture group, numbered or named |
(?:…) | A group that does not capture, for applying a quantifier or | to several items |
\1 \k<name> | The same text that group 1 or a named group matched earlier |
a|b | Either a or b |
(?=…) (?!…) | Lookahead: followed by, or not followed by, something, without including it in the match |
(?<=…) (?<!…) | Lookbehind: preceded by, or not preceded by, something |
\p{L} \p{Lu} | Any letter in any script; an uppercase letter (needs the u or v flag) |
Worked Example: Dates in a Log
To find ISO dates such as 2025-04-02 and pick out their parts, use the Date preset:
\b(?<year>\d{4})-(?<month>0[1-9]|1[0-2])-(?<day>0[1-9]|[12]\d|3[01])\b\bat both ends stops it matching inside a longer number.(?<year>\d{4})captures four digits as a group named year.0[1-9]|1[0-2]allows only months 01 to 12, so2025-13-40in the sample text is not matched.0[1-9]|[12]\d|3[01]allows days 01 to 31. It does not know that February has 28 or 29 days; check real dates in code after matching.
In JavaScript, m.groups.year then gives the year of each match, and replacing with $<day>/$<month>/$<year> rewrites the dates in day-month-year order.
Tips for Faster, Safer Patterns
- Be specific.
[^"]*to read up to the next quote is faster and more predictable than.*?", and both are far safer than nested repetition like(.*)*. - Anchor when you validate. To check that a whole value is a number, use
^\d+$; plain\d+also matches insideabc123. - Use non-capturing groups
(?:…)when you only need grouping, so the numbering of the groups you do need stays simple. - Reset lastIndex. A regex with g or y remembers where it stopped, so calling
re.test()twice on the same text can give true then false. Create a new regex or setre.lastIndex = 0between uses.
Related Tools
To compare a text before and after a find-and-replace, use the diff checker. For tidying the JSON a pattern pulls out of a log, use the JSON formatter, and to escape matched text for a link, the URL encoder.
Frequently Asked Questions
Which regex flavour does this tester use?
JavaScript (ECMAScript), run by your browser's own engine. Results match what the same pattern does in JavaScript and Node.js. Most everyday syntax is shared with Python, PHP (PCRE), Java and .NET, but some features differ: JavaScript has no possessive quantifiers (a++), atomic groups or \A and \Z anchors, while its lookbehind accepts any length, which Python's re module does not. Test patterns for other languages in that language before relying on them.
Why does my regex find only one match?
Without the g (global) flag, a JavaScript regex stops at the first match. Turn on g to find every match. The match count shows a reminder when g is off.
What do the flags g, i, m, s, u, v and y mean?
g finds all matches; i ignores upper and lower case; m makes ^ and $ match at each line instead of only the start and end of the whole text; s lets . match line breaks; u turns on full Unicode handling and \p{…} property classes; v is a newer Unicode mode that also allows set operations inside [ ]; 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 a special meaning are . * + ? ^ $ { } ( ) | [ ] and \ itself, so a literal dot is \. and a literal ( is \(. Inside a JavaScript /…/ literal, a forward slash must be written \/ too; the Code tab adds those escapes for you.
How do I use capture groups in a replacement?
In the Replace tab, $1, $2 and so on insert what each numbered group matched, $<name> inserts a named group, $& inserts the whole match and $$ writes a single dollar sign. For example, replacing (\d{4})-(\d{2})-(\d{2}) with $3/$2/$1 turns 2025-04-02 into 02/04/2025.
What is catastrophic backtracking?
Some patterns, usually with one repetition inside another such as (a+)+ or (.*)*, can take exponentially longer as the text grows when there is no match: each extra character doubles the work. On a server, that can let one crafted input tie up the CPU, a problem known as ReDoS. This tester runs patterns in a background worker and stops them after 2 seconds, so you can see the problem without the page freezing.
Is there a regex that validates every email address?
Not a practical one. The full address syntax allows quoted names, comments and IP literals that no short pattern handles. A simple check such as the Email preset catches typos; to know an address really works, send a confirmation email to it.