Regex Tester

Test a JavaScript regular expression against your own text and see every match, position and capture group.

How to use

  1. Type your pattern without slashes, for example \d+.
  2. Add flags such as g (all matches), i (ignore case) or m (multiline).
  3. Paste your text and press Test.

Good to know

This uses the regular expression engine of your browser, so it follows JavaScript syntax. Explore more on the Tools page.

What is a regular expression?

A regular expression, often shortened to regex or regexp, is a compact pattern that describes a set of strings. Instead of searching for a fixed word, you describe the shape of the text you want. For example, the pattern \d{3}-\d{4} matches three digits, a dash and four more digits, which is the shape of many phone numbers. Regular expressions are built into JavaScript, Python, PHP, Java and almost every other language, as well as text editors and command line tools, and they save huge amounts of time when you need to validate, search or clean text.

This regex tester lets you try patterns safely before you put them into your code. Type the pattern, choose flags, paste your sample text and the tool lists every match with its position and any capture groups. If the pattern has a syntax mistake, you see the error message from the browser right away.

How to use the tester

  1. Enter the pattern without the surrounding slashes.
  2. Set the flags. Use g to find all matches, i to ignore upper and lower case, m so that ^ and $ match at each line, and s so that the dot also matches new lines.
  3. Paste your text in the test box.
  4. Press Test and read the list of matches, each with its index and groups.

Regex building blocks you should know

  • . matches any single character except a line break.
  • \d matches a digit, \w matches a letter, digit or underscore, and \s matches whitespace. Their capital forms mean the opposite.
  • * means zero or more, + means one or more and ? means zero or one of the previous item.
  • {n} and {n,m} set an exact or ranged number of repeats.
  • [abc] matches one of the listed characters and [a-z] matches a range. [^abc] matches anything else.
  • ^ and $ anchor the pattern to the start and end of the text or line.
  • ( ) creates a capture group, and (?: ) groups without capturing.
  • | works as an or between alternatives.
  • \b marks a word boundary.

Useful examples to try

To find numbers in a sentence, use \d+ with the g flag. To pick out simple email addresses, try [\w.]+@[\w.]+\.\w+. To match a date such as 2026-10-17, use (\d{4})-(\d{2})-(\d{2}), and you will see the year, month and day as groups one, two and three. To find repeated words, try \b(\w+)\s+\1\b, which uses a back reference to the first group. To match hex colours, use #[0-9a-fA-F]{6}\b. Test each one on your own text and adjust it until the matches are exactly what you want.

Greedy and lazy matching

By default, quantifiers are greedy, which means they take as much text as they can. If you use <.+> on a string like <b>bold</b>, the match covers the whole string. Adding a question mark makes it lazy, so <.+?> stops at the first closing bracket and finds each tag separately. This is one of the most common surprises for beginners, and a tester makes the difference easy to see.

Common mistakes

  1. Forgetting to escape special characters. To match a literal dot or bracket, put a backslash before it.
  2. Forgetting the g flag and wondering why only the first match shows.
  3. Using a pattern that is too loose. Validation of emails or phone numbers is hard, so anchor your pattern and test with edge cases.
  4. Writing patterns that can take a very long time on certain inputs, known as catastrophic backtracking. Avoid nested quantifiers such as (a+)+ on untrusted text.
  5. Assuming every language behaves the same. Small differences exist, for example in look behind support or named groups. This tool follows your browser, so it matches JavaScript.

Using your pattern in code

In JavaScript you can write a literal such as /\d+/g or build one with new RegExp("\\d+", "g"), where the backslash needs doubling inside the string. The method text.match(re) returns matches, re.test(text) returns true or false, and text.replace(re, "x") substitutes. When you are cleaning data, our Remove Duplicate Lines, Remove Extra Spaces and Text Diff Checker may also help.

Privacy

The tester runs completely in your browser. The text and patterns you enter are not sent anywhere, so you can safely try sample data. Avoid pasting real passwords or secrets anyway as a good habit.

Frequently asked questions

Which regex flavor does this use?

The JavaScript flavor of your browser.

Why do I only get one match?

Add the g flag to find all matches.

How do I match a literal dot?

Use a backslash before it, written as \..

Can I see capture groups?

Yes. Every group appears under its match.

Is there a limit?

The tool lists up to 500 matches to keep your browser responsive.

More patterns you can copy

  • ^\d{10}$ matches a ten digit phone number with nothing else around it.
  • ^[A-Z]{5}\d{4}[A-Z]$ matches the shape of a PAN card number.
  • https?:\/\/[^\s]+ finds web addresses in a block of text.
  • \s{2,} finds places with two or more spaces in a row.
  • ^\s+|\s+$ finds spaces at the start and end of a line, useful with the g and m flags.
  • (?<=\$)\d+ finds numbers that follow a dollar sign, using a look behind.

Understanding groups and named groups

Parentheses do two jobs. They group part of the pattern so that a quantifier can apply to the whole group, and they capture the matched text so that you can use it later. Modern JavaScript also supports named groups, written as (?<year>\d{4}), which makes code easier to read because you can access match.groups.year instead of counting brackets. Use the tester to confirm which group holds which part of the match.

Debugging a pattern step by step

  1. Start with a very small pattern that matches something.
  2. Add one piece at a time and test again after every change.
  3. Use sample text that contains both strings that should match and strings that should not.
  4. Check edge cases such as empty strings, extra spaces and unusual characters.
  5. Once the pattern works, add anchors so that it cannot match part of a longer word.

When not to use regular expressions

Regex is excellent for finding patterns, but it is a poor tool for parsing nested structures such as full HTML or deeply nested JSON. For those, use a real parser. Our JSON Formatter is a better choice for checking JSON. Also remember that complicated patterns are hard to read months later, so add a comment in your code that explains what they do.

Scroll to Top