Regex Tester: Test Regular Expressions Online
Use this regex tester to build and debug regular expressions. Type a pattern and some test text, and see matches and capture groups light up live. Turn flags on or off, try find and replace, and use the cheat sheet when you get stuck.
Regex Tester
Live regular expression matching.
How to use the Regex Tester
- Type your regular expression (without slashes).
- Tick the flags you need: g (all matches), i (ignore case), m (multiline), s (dot matches newline), u (Unicode).
- Enter the test text; matches are highlighted live.
- Try a replacement with $1, $2 for groups.
How it works
The pattern is compiled with JavaScript’s RegExp and run over the test text. Each match is highlighted and listed with its position, numbered groups and named groups. The replace box shows the result of String.replace with your pattern and flags.
Example
The pattern (\d+)-(\d+) finds 12-34 and 5-6 in the sample text, and replacing with $2-$1 gives 34-12 and 6-5.
Frequently asked questions
Which regex flavor is this?
JavaScript (ECMAScript), which is close to PCRE for common patterns.
How do I match a literal dot?
Escape it: \.
What are named groups?
Groups written (?<name>...) that you can read by name.
See also: JSON Formatter.
Test a regex
How to use it
- Type your pattern.
- Paste test text.
- Set flags.
- Check matches and groups.
More questions
Can I test replace?
Yes. Add a replace pattern to test find and replace.
Is my text uploaded?
No. Everything stays in your browser on your device.
Related tools: Find and Replace Text Online, Email Extractor, JSON Formatter & Validator.
A ZIP code pattern and a phone swap
Type the pattern without slashes, tick the flags you need (g is on by default), paste your test text and watch the matches highlight. Use $1, $2 in the replace box to reuse groups. To compare text before and after a replacement, use the Text Compare.
Worked example: the pattern \b\d{5}(?:-\d{4})?\b on "Ship to 90210 or 10001-1234, not 1234 or 123456." finds 2 matches, 90210 at position 8 and 10001-1234 at position 17. The pattern (\d{3})-(\d{3})-(\d{4}) with the replacement ($1) $2-$3 turns 212-555-0147 into (212) 555-0147.
More answers
Why does my replacement change only the first match?
Replacement follows the g flag. With g unticked the tool reports "first match only" and replaces just that one, so "212-555-0147 or 646-555-0199" changes only the first number. Tick g to change both.
How do I match a 5-digit ZIP code with an optional +4?
Use \b\d{5}(?:-\d{4})?\b. It matches 90210 and 10001-1234, but skips 1234 and 123456 because the word boundaries stop it from matching part of a longer number.