Regex Tester and Debugger - Free Online Tool

Regex Tester & Debugger

Write and test regular expressions with real-time match highlighting.

/ /

Match Details

Enter a pattern and test string to see matches.
Regex Cheatsheet
. Any character
\d Digit [0-9]
\w Word char
\s Whitespace
\b Word boundary
^ Start of string
$ End of string
* 0 or more
+ 1 or more
? 0 or 1
{n,m} n to m times
(abc) Capture group
[abc] Char class
[^abc] Negated class
a|b Alternation

This regex tester and debugger lets you type a regular expression, paste a test string and see every match highlighted as you type. It is built for developers, SEOs and analysts who need to check a pattern before it goes into code, a redirect rule or a bulk find-and-replace job. Switch to Replace mode to preview the substitution.

What Is a Regular Expression?

A regular expression (regex) is a compact pattern that describes a set of strings, so you can find, validate or replace text without listing every possible value. For example, \d{3}-\d{4} means "three digits, a hyphen, then four digits," and it matches 555-1234 but not 55-12345.

Patterns combine literal characters with special tokens. The Regex Cheatsheet panel under the tester lists the ones you will use most:

  • . matches any character, \d a digit, \w a word character and \s whitespace.
  • ^ and $ anchor a match to the start or end of the string, and \b marks a word boundary.
  • * (0 or more), + (1 or more), ? (0 or 1) and {n,m} (n to m times) control repetition.
  • (abc) creates a capture group, [abc] a character class, [^abc] a negated class and a|b an alternation.

What do the g, i, m and s flags do?

Flags change how the whole pattern behaves, and the tester gives you four checkboxes next to the pattern field.

  • g (global) finds every match instead of stopping at the first. It is checked by default.
  • i (ignore case) treats "Seo" and "SEO" as the same.
  • m (multiline) makes ^ and $ match at the start and end of each line, not only of the whole string.
  • s (dot matches newlines) lets . match line breaks too.

The tester follows JavaScript (ECMAScript) regex syntax. It is close to what many other languages accept, but a few features from other flavors, such as inline flags like (?i) or possessive quantifiers, are not available.

How Do You Use the Regex Tester and Debugger?

You can test a pattern in under a minute: enter it, paste some text and read the highlighted result. Nothing needs to be submitted, because the output refreshes every time you change a field.

  1. Type your pattern into the Regular Expression field. The slashes around it are already there, so enter only the pattern, for example [A-Za-z]+.
  2. Tick or untick the g, i, m and s flag boxes to suit what you want to match.
  3. Paste or type your sample text into the Test String box. Use real data, not a tidy example, so edge cases show up.
  4. Stay on Match to see highlighted matches in the Result area and the list under Match Details.
  5. Click Replace to reveal the Replacement field, then enter replacement text. Use $1, $2 and so on to insert capture groups.
  6. Open Regex Cheatsheet if you need a reminder of a token, then adjust the pattern until the highlights are exactly what you want.

If either the pattern or the test string is empty, the tool waits and shows a prompt instead of results. That is normal, not an error.

Worked Example: Reformatting Phone Numbers

Say you have the text Call 555-1234 or 555-9876 today. and you want to find the local numbers. Enter (\d{3})-(\d{4}) as the pattern and leave the g flag on.

In Match mode, the tester highlights two matches: 555-1234 and 555-9876. Each match gets its own color, so you can see where one ends and the next begins. If you untick g, only the first number is found, which is the quickest way to learn what the global flag does.

Now switch to Replace and enter $2-$1 as the replacement. The result reads Call 1234-555 or 9876-555 today. Group 1 captured the first three digits, group 2 the last four, and the replacement swapped them. The swap is not useful for phone numbers, but it proves your groups capture what you think they do, which is the point of testing before you run the pattern on a real file.

How Do You Read the Results and Fix Problems?

A good result is one where the highlights cover exactly the text you intended, nothing more and nothing less. Check three things each time: what is highlighted, what is not, and what the Match Details panel lists.

Nothing is highlighted

No highlights usually means the pattern is too strict or a flag is missing. Check the case first (turn on i), then look for characters that need a backslash, such as \. for a literal dot or \( for a literal parenthesis. If the text has line breaks, anchors may need the m flag.

Too much is highlighted

Over-matching almost always comes from greedy quantifiers. The pattern <b>.*</b> will swallow everything between the first opening tag and the last closing tag on a line. Add a ? after the quantifier (.*?) to make it match as little as possible, or use a negated class like [^<]*.

Only one match appears

If you expected several matches and see one, the g flag is probably off. Tick it and the rest appear.

The replacement shows a literal $1

If you see $1 in the output, your pattern has no capture group. Wrap the part you want to reuse in parentheses, like (\d+), and the replacement will fill in.

The pattern gives an error or never finishes

Unbalanced brackets, a stray * at the start or an unclosed group will stop the pattern from running. Remove the last thing you typed and add it back piece by piece. If the tool says your browser cannot evaluate patterns, open the page in an up-to-date browser.

Who Is a Regex Tester For?

Anyone who has to match text by rule will save time here. Typical situations include:

  • Developers validating form input such as zip codes, usernames or dates before shipping the check.
  • SEOs pulling product IDs, parameters or slugs out of a crawl export, or planning URL patterns for a site migration. When you are ready to turn a pattern into server rules, the .htaccess redirect generator writes the redirect code for you.
  • Data analysts cleaning messy columns, stripping prefixes or extracting numbers from log lines.
  • Writers and editors running a bulk find-and-replace to fix spacing, dashes or repeated words.
  • Learners who want to see instantly what each token does, with the cheatsheet beside the result.

If you need to compare the text before and after a big replacement, paste both versions into the code diff tool to review every change line by line.

Best Practices and Common Mistakes

Build patterns in small steps. Start with the simplest piece that matches, confirm the highlight, then add the next part. A pattern you grew one token at a time is far easier to debug than a long one pasted in whole.

  • Test with bad input too. Add lines that should not match. A zip-code pattern that highlights "123456" is too loose; anchoring it with ^\d{5}$ fixes that.
  • Escape special characters. The characters . * + ? ( ) [ ] { } | ^ $ \ have special meaning. To match them literally, put a backslash before them.
  • Prefer specific classes to the dot. \d+ is safer than .+ when you expect digits.
  • Anchor when you are validating. Without ^ and $, a pattern can match part of a longer string and still look correct.
  • Use word boundaries. \bcat\b matches "cat" but not "category."
  • Keep sample text realistic. Include the odd spacing, capital letters and punctuation your real data has.
  • Tidy surrounding code. If the pattern lives inside a longer script, the code beautifier can make it easier to read before you paste the pattern in.

What Are the Limitations?

The tester gives you a reliable preview of how a pattern behaves under JavaScript regex rules, which are shared by browsers and many other environments. If your final code runs in another language, always confirm there as well, because lookbehind support, named group syntax and flags can differ between flavors.

Only the g, i, m and s flags are offered here. Patterns that depend on other flags will not be testable. Very large test strings or patterns with heavy backtracking can be slow to evaluate, so test with a representative sample rather than a whole file. Also remember that file-ignore rules and glob patterns, like those in a .gitignore file, use their own wildcard syntax and are not regular expressions.

Paste your pattern and sample text into the regex tester above and watch the highlights change as you edit. When the matches look right, copy the pattern into your project, and browse more utilities in the web developer tools collection for your next task.

Frequently Asked Questions

What is a regex tester and debugger?
A regex tester and debugger lets you try a regular expression against sample text and see what it matches. This tool highlights matches as you type, lists them under Match Details, and previews replacements, so you can fix a pattern before using it in code.
How do I test a regular expression online?
Type your pattern into the Regular Expression field, paste text into the Test String box, and read the highlighted Result. Choose flags with the g, i, m and s checkboxes. Results update live, so there is no submit button to press.
How do I test a regex replacement with capture groups?
Click Replace, then enter your text in the Replacement field using $1, $2 and so on for captured groups. For example, the pattern (\d{3})-(\d{4}) with the replacement $2-$1 turns 555-1234 into 1234-555 in the Result area.
What do the g, i, m and s flags mean?
The g flag finds all matches, i ignores letter case, m makes ^ and $ work on each line, and s lets the dot match line breaks. The tester shows these four as checkboxes, and g is on by default.
Why is my regex not matching anything?
Most often the pattern is too strict, the case differs, or a special character is missing its backslash. Turn on the i flag, escape characters like a dot or parenthesis, and build the pattern in small pieces, checking the highlight after each addition.
Is this regex tester free, and which regex syntax does it use?
Yes, the regex tester is free and needs no sign-in. It follows JavaScript (ECMAScript) regex syntax, so features from other flavors, such as inline flags like (?i), may not work. Confirm the final pattern in your own language if it differs.
Recommended

Explore VPN options

A VPN changes your network exit. It does not guarantee anonymity.

Hide Your IP Encryption Network coverage
Protect My IP Now

Evaluation and limits

JavaScript regular expressions run in an isolated worker. Global searches return up to 5,000 matches. Evaluation stops after 500 ms. For example, /a/g finds three matches in aaa; without g it finds the first match.

Implementation reviewed: 4 October 2026. Source documentation