Regex Validator
Test JavaScript regular expressions against sample text, inspect live matches, review capture groups, and preview replacement output. Free, private, and built for fast debugging.
Regex pattern
Flags
Test text
Validation result
Valid regex
Matches
3
Highlighted text
Matches and groups
Replace preview
Contact [email hidden] for product questions. For billing, email [email hidden] or [email hidden]. Invalid examples: support@, @example.com, and plain text.
How to test a regular expression
Write a pattern, choose flags, and see every match, group and replacement on your own text.
- 01
Write the pattern without slashes
Type the part between the slashes only, such as \d{4}-\d{2}-\d{2}, not /\d{4}/. The sample pattern finds email addresses so you can see the output first.
- 02
Switch on the flags you need
g finds every match instead of the first, i ignores case, m makes ^ and $ work per line, s lets . match line breaks, u turns on full Unicode, and y anchors each match where the last ended.
- 03
Paste test text and read the matches
Each match shows its position in the text and any capture groups. If the pattern itself is invalid, the error message from the JavaScript engine appears instead.
- 04
Try a replacement
The replacement box previews String.replace on your text. Use $1, $2 for numbered groups and $<name> for named ones.
Worked examples
The sample pattern, \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b with the g and i flags, run on "Contact [email protected] or [email protected] today." finds two matches: [email protected] at position 8 and [email protected] at position 33. Without the i flag it finds none, because the character classes only list capital letters.
Replacements can rearrange what they capture. The pattern (\d{4})-(\d{2})-(\d{2}) with the replacement $3/$2/$1 turns 2026-10-31 into 31/10/2026. Each pair of brackets is a group, numbered from the left.
What each flag changes
Flags change how the whole pattern behaves. The same pattern can match everything, nothing or something in between depending on them.
| Flag | Effect | Typical use |
|---|---|---|
| g (global) | Find all matches, not just the first | Counting or highlighting every email in a page |
| i (ignore case) | A matches a, É matches é | Matching words regardless of capitals |
| m (multiline) | ^ and $ match at each line, not just the whole text | Checking every line of a log is a number |
| s (dot all) | . also matches line breaks | Grabbing a block that spans lines |
| u (unicode) | Treats emoji and other astral characters as one character; enables \p{…} | Matching \p{L} letters in any language |
| y (sticky) | Each match must start exactly where the last one ended | Writing a tokenizer |
The m flag catches people out most. ^\d+$ tested against "12" then a new line and "ab" fails without m, because the whole text isn't digits. With m it succeeds, because the first line on its own is.
Where regex testing saves time
Writing form validation
Test a pattern against the inputs you expect and the ones you don't, before it rejects real customers' postcodes or names.
Search and replace in an editor
VS Code and most editors use the same syntax. Check the pattern and the $1 replacement here, then paste both in.
Pulling values out of logs
Capture IDs, status codes or timestamps with groups, and check the matches on a few sample lines first.
Limits and pitfalls
This is JavaScript's regex engine. Most syntax is shared with Python, Java and PCRE, but not all: possessive quantifiers like a++ and atomic groups (?>…) aren't supported, and lookbehind works in modern browsers but not in some older engines. Test in the language you'll deploy to if it isn't JavaScript.
Some patterns take exponential time on certain inputs, known as catastrophic backtracking. ^(a+)+$ against 27 a's followed by a b took about 3.7 seconds to fail in our test, and each extra a roughly doubles it. The page runs the pattern directly, so a pattern like that will freeze the tab while it works. Avoid nesting quantifiers such as (a+)+ or (.*)*.
- Only the first 100 matches are listed.
- A pattern that matches empty text, such as a*, reports only its first match.