tool
Regex Tester
Write a regular expression, test it against your text, and instantly see matches, capture groups, indexes
enter some test text to see matches
enter a regex to start testing
Test and debug JavaScript regular expressions live
Type a pattern, toggle flags and paste the text you want to search. Every match is highlighted as you type, and a match list shows each value with its start index, end index, length and capture groups. The tester uses your browser's own JavaScript RegExp engine, so a pattern that works here behaves the same way in String.match(), replace() or test() in your front-end or Node.js code.
What can you do?
- 1. Live match highlighting
Matches are highlighted inside your test text the moment the pattern, flags or text change, with a counter showing how many were found. - 2. Detailed match list
Inspect each match's value, index, end position, length and numbered capture groups to see exactly what your groups captured. - 3. All six common flags
Toggle g, i, m, s, u and y and see immediately how each one changes the result. - 4. Escape special characters
Turn literal text such as a price, a file path or a URL into a safe pattern with one click. Characters like . * + ? ( ) [ ] { } | ^ $ and \ are escaped for you. - 5. Starter patterns
Load examples for emails, URLs, phone numbers, hex colours, numbers and words, each with a short explanation, then adapt them to your data. - 6. Copy as a regex literal
Copy the pattern in /pattern/flags form, ready to paste into JavaScript or TypeScript code.
Why test a regex before putting it in your code?
Regular expressions fail quietly. A pattern that is slightly too greedy matches more than you intended, a missing anchor lets invalid input through, and a forgotten g flag returns only the first result. None of these throw an error; they simply give wrong answers.
Testing against real sample text, including the edge cases you expect to reject, shows exactly what the pattern does before it ends up in form validation, a log parser or a search-and-replace across your codebase.
How to test a regular expression
- 1. Enter the pattern without slashes
Type\d{3}-\d{4}, not/\d{3}-\d{4}/. Flags are set with the toggles instead of after the closing slash. - 2. Choose your flags
Turn on g to find every match rather than just the first, plus any other flags you need. - 3. Paste realistic test text
Include lines that should match and lines that shouldn't. Testing the failures is just as important as testing the successes. - 4. Check the matches and groups
Read the match list to confirm each match and capture group contains exactly what you expect, then copy the regex into your code.
JavaScript regex flags explained
| Flag | Name | What it does | Example use |
|---|---|---|---|
g | Global | Finds all matches instead of stopping after the first. | Extract every email address from a page |
i | Ignore case | Treats upper and lower case letters as equal. | Match error, Error and ERROR |
m | Multiline | Makes ^ and $ match at the start and end of every line. | Find lines starting with TODO |
s | Dot all | Lets . match line breaks too. | Match a block that spans several lines |
u | Unicode | Treats emoji and other astral characters as single characters and enables \p{…} classes. | Match Tamil or other scripts with \p{L} |
y | Sticky | Only matches at the exact position where the previous match ended. | Writing a tokenizer |
Regex cheat sheet
The building blocks you'll use most often:
| Token | Matches | Example |
|---|---|---|
\d \w \s | A digit, a word character (letter, digit or _), whitespace | \d+ |
\D \W \S | The opposite of each of the above | \S+ |
. | Any character except a line break (unless s is on) | a.c |
[abc] [^abc] [a-z] | One character from a set, not in a set, or in a range | [A-F0-9] |
* + ? | Zero or more, one or more, zero or one | colou?r |
{n} {n,} {n,m} | Exactly n, at least n, between n and m times | \d{6} |
*? +? | Lazy versions that match as little as possible | <.+?> |
^ $ \b | Start, end, word boundary | ^\w+$ |
(…) (?:…) (?<name>…) | Capturing, non-capturing and named groups | (\d{4})-(\d{2}) |
a|b | Either alternative | jpg|png|webp |
(?=…) (?!…) | Lookahead: followed by, not followed by | \d+(?=px) |
(?<=…) (?<!…) | Lookbehind: preceded by, not preceded by | (?<=₹)\d+ |
JavaScript regex vs other regex flavors
Most regex syntax is shared across languages, but a few features differ. Python writes named groups as (?P<name>…) while JavaScript uses (?<name>…). PCRE (PHP) and Java support possessive quantifiers like a++ and the anchors \A and \Z, which JavaScript does not. If you are porting a pattern from another language, test it here and adjust any syntax JavaScript rejects.
When you move a pattern into code, remember that a regex literal like /\d+/ needs no extra escaping, but the string form needs doubled backslashes: new RegExp("\\d+").
Frequently asked questions
Why does my regex only find the first match?
The g (global) flag is off. Without it, a JavaScript regex stops after the first match. Turn on g to find every occurrence.
Why don't ^ and $ match at the start of each line?
By default ^ and $ only match at the very start and end of the whole text. Turn on the m (multiline) flag to make them match at every line break.
Is the built-in email pattern enough to validate email addresses?
It is a quick check for an email-like shape and is good for finding addresses in text. For sign-up forms, combine a simple pattern with a confirmation email, because no practical regex can tell you whether an address really exists.
Why is my pattern slow or making the page freeze?
Nested quantifiers such as (a+)+ or (.*)* can cause catastrophic backtracking, where the engine tries an enormous number of combinations on text that almost matches. Make quantifiers more specific or remove the nesting.
Is my test text sent to a server?
No. Matching runs in your browser with the built-in RegExp engine, so patterns and text never leave your device.
Related tools
Building something that needs random IDs or test values? Try the token generator.
- JavaScript Formatter & Validator – Format, lint and minify JavaScript snippets.
- Diff Checker – Compare two versions of text or code line by line.
- Secure Token Generator – Create random secrets, API keys, UUIDs and hex strings.
- JSON Formatter & Validator – Pretty-print, validate and minify JSON.