Regex tester

Flags
Examples:

This tester uses JavaScript regular expressions, and JavaScript regex syntax differs from some other languages (for example Python or PCRE): features such as lookbehind, named groups and Unicode property escapes exist in modern JavaScript but behave differently elsewhere, and \d matches ASCII digits only unless the u flag is set. Turn on the g flag to find all matches; without it only the first match is shown. To keep the page responsive, the pattern is limited to 500 characters, the test text to 50,000 characters, and the results to 1,000 matches. A pattern with a quantifier inside a quantified group (such as (a+)+) can take a very long time on long text — the tester warns about those, and a shorter test text is the safe way to try one.

What is the Regex Tester?

The Regex Tester is a free online tool for testing a JavaScript regular expression against sample text. Enter your pattern, your test text and your flags, and it shows you the matches with their positions and capture groups, the total match count, and the test text with the matches highlighted. Common examples — email address, URL, date, HTML tag and number — are one click away.

It is made for anyone who works with patterns: developers validating input, writers extracting data from text, students learning regular expressions, and anyone debugging a pattern that does not match what it should. There is nothing to install and nothing to sign up for. Everything runs in your browser, and your pattern and text never leave your device.

One thing to know: this tester uses JavaScript regular expressions, and JavaScript regex syntax differs from some other languages, such as Python or PCRE. Features like lookbehind, named groups and Unicode property escapes exist in modern JavaScript but behave differently elsewhere, and d matches ASCII digits only unless the u flag is set.

How to use the Regex Tester

  1. Enter your regular expression in the box labelled “Regular expression”. The tool comes with an email-address pattern already loaded.
  2. Choose your flags. The flags are checkboxes: g for global (find all matches), i for case-insensitive, m for multiline (^ and $ match line starts and ends), s for dotAll (. matches line breaks too), and u for Unicode mode. The g flag is on by default.
  3. Enter your test text in the box labelled “Test text”.
  4. Click “Test”. The results show the match count, each match with its position and capture groups, and the test text with the matches highlighted.
  5. Copy expression copies your pattern, Clear empties the boxes, and Reset brings back the email example. The Examples buttons load a ready-made pattern and text for email addresses, URLs, dates, HTML tags and numbers.

Worked example

The sample pattern is the classic email pattern:

[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}

The sample text is:

Email hello@example.com or support@allabouthtml.com today.

With the g flag on, click “Test” and the tool reports 2 matches:

MatchTextPosition
1hello@example.com6–23
2support@allabouthtml.com27–51

Both addresses are highlighted in the test text. Now turn the g flag off and test again: only the first match is shown. That is the difference the g flag makes — without it, the tester stops after the first match, and without it in your own code, a search or replace stops after the first match too.

How the pattern works

Breaking the email pattern down, piece by piece:

  • [a-zA-Z0-9._%+-]+ — one or more characters from the set: letters, digits, dot, underscore, percent, plus and hyphen. This is the part before the @.
  • @ — a literal at-sign.
  • [a-zA-Z0-9.-]+ — one or more letters, digits, dots and hyphens. This is the domain name.
  • . — a literal dot. The backslash matters: an unescaped . would match any character.
  • [a-zA-Z]{2,} — two or more letters. This is the top-level domain, like com or org.

It is a practical pattern, not a perfect one — no short regex validates every legal email address — but it catches the addresses people actually type, which is what most validation needs.

Where a regex tester earns its keep

Validating input

The most common use. Before you put a pattern into a form — an email field, a phone number, a postcode — test it here against real examples: valid ones it should accept, and invalid ones it should reject. The highlighted matches make it obvious when a pattern accepts something it should not, or rejects something it should accept.

Extracting data from text

A pattern with the g flag finds every occurrence, not just the first. Pull all the email addresses out of a block of text, all the dates, all the prices — then copy the matches. The positions and capture groups tell you exactly where each match sits, which is what you need when you are building the extraction into code.

Learning regular expressions

Regex is hard to learn from a cheat sheet alone, because you cannot see what a pattern actually does until you run it. This tool is the feedback loop: change one character in the pattern, click “Test”, and watch the matches change. The example buttons give you five working patterns to start from and pull apart.

Tips for writing patterns that work

  • Turn on g to find all matches. Without the global flag, only the first match is shown — and in your own code, a search or replace without g stops after the first match too. If you expect more than one result and you only see one, check the g flag first.
  • Escape the dot. A . in a pattern matches any character, not a literal dot. The email pattern uses . for the dot before the domain ending, and that backslash is doing real work. If your pattern matches things it should not, an unescaped dot is a common cause.
  • Watch out for nested quantifiers. A pattern with a quantifier inside a quantified group, such as (a+)+, can take a very long time on long text — this is catastrophic backtracking, and a single JavaScript regex run cannot be interrupted. The tester warns about those patterns. If you see the warning, try the pattern on a shorter test text first, and rewrite it to avoid the nesting.
  • Know your flags. i makes the match case-insensitive, which matters for text like email addresses. m changes ^ and $ to match line starts and ends instead of the whole text. s lets . match line breaks too. u switches on Unicode mode, which changes what d and other escapes match. The wrong flag is a common reason a correct-looking pattern fails.
  • Remember the limits. The pattern is limited to 500 characters, the test text to 50,000 characters, and the results to 1,000 matches. Those limits keep the page responsive. If your real text is longer than 50,000 characters, test the pattern on a representative sample of it here, then run it on the full text in your own code.

Frequently asked questions

Which regular expression flavour does this tester use?

JavaScript. The pattern is run as a JavaScript RegExp, so the syntax and behaviour are JavaScript’s. That matters because JavaScript regex differs from some other languages — for example Python or PCRE. Features like lookbehind, named groups and Unicode property escapes exist in modern JavaScript but behave differently elsewhere, and d matches ASCII digits only unless the u flag is set.

What do the flags do?

g (global) finds all matches instead of stopping at the first. i makes the match case-insensitive. m (multiline) makes ^ and $ match the start and end of each line, not just the whole text. s (dotAll) makes . match line breaks as well as other characters. u (Unicode) switches on Unicode mode, which affects how escapes like d behave and allows Unicode property escapes.

Why did my pattern trigger a warning?

Because it has a quantifier inside a quantified group, such as (a+)+. That shape can cause catastrophic backtracking: on long text, the engine tries an enormous number of combinations before giving up, and a single JavaScript regex run cannot be interrupted, so the page would freeze. The tester warns you instead of freezing. Try the pattern on a shorter text, or rewrite it to remove the nesting.

Is there a limit on the pattern or the text?

Yes. The pattern is limited to 500 characters, the test text to 50,000 characters, and the results to 1,000 matches. Those are practical limits to keep the page responsive. Most real patterns are far shorter than 500 characters, and 50,000 characters of test text is more than enough to check a pattern properly.

Does my pattern or text leave my browser?

No. Everything runs in your browser. Nothing is uploaded, stored or sent anywhere, and there is no account or sign-up. You can test patterns against private or sensitive text without worrying about where it goes.

Conclusion

Regular expressions are powerful and unforgiving: one wrong character and a pattern matches everything or nothing, and the only way to know is to run it. This Regex Tester gives you that run in seconds — the matches, their positions, their capture groups and the highlighted text — with five ready-made examples to start from and a warning when a pattern risks freezing the page. Test your pattern here before you put it in your code. And when you need to find and replace text rather than just match it, the Word and Character Counter will tell you exactly how much text you are working with.

Related Tools