Toolstia / Regex tester

Regex tester

This page runs a JavaScript regular expression against your sample text and shows you exactly what it matched. Hits are highlighted in the text, and a table lists each match with its starting position and every capture group, so you can see why a pattern behaves the way it does before you paste it into code.

It is useful for validating input formats, writing search-and-replace rules, extracting fields from log lines, and debugging a pattern that matches too much or too little. Turn on the replacement box to preview the substituted result, using the same $1, $2 references you would use in a script. Matching is done by your browser's own engine, in a background worker that is stopped after 1.5 seconds.

Flags

This uses your browser's JavaScript regular expressions. Other languages, such as Python, PHP or Java, differ in small ways. Nothing you type is sent anywhere.

How it works

  1. Type your pattern and choose the flags you need.
  2. Paste the text to search.
  3. Read the highlighted matches and the table below.

Flags

g finds every match instead of just the first. i ignores upper and lower case. m makes ^ and $ match at each line. s lets the dot match line breaks. u turns on full Unicode handling, which you need for emoji and many non-Latin scripts.

Groups and replacement

Parts of the pattern in brackets are capture groups. The table shows each group as $1, $2 and so on. In the replacement box you can use the same $1, $2 to move text around.

A safety net

Some patterns, such as (a+)+ on a long run of a letters, can take almost forever to fail. The test runs in a background thread and stops after 1.5 seconds, so your page never freezes.

JavaScript flavour

This uses the JavaScript engine in your browser. Python, PHP, Java and others support slightly different features, such as lookbehind or named group syntax, so check the details if you will use the pattern elsewhere.

A worked example with groups and replacement

Take the text Invoice 2026-11-14 and 2027-01-05 and the pattern (\d{4})-(\d{2})-(\d{2}) with the g flag. The table shows two matches. For the first, group 1 is 2026, group 2 is 11 and group 3 is 14. In the replacement box, $3/$2/$1 turns the text into Invoice 14/11/2026 and 05/01/2027.

Untick g and run it again: the pattern now finds only the first date, and the replacement changes only that one, giving Invoice 14/11/2026 and 2027-01-05. Forgetting g is the most common reason a replacement seems to work on just one item.

Greedy versus lazy matching

Quantifiers such as + and * grab as much text as they can. On <b>bold</b> and <i>it</i>, the pattern <.+> matches the whole string from the first < to the last >, as a single match. Adding a question mark makes the quantifier lazy: <.+?> returns four separate matches, <b>, </b>, <i> and </i>.

When a pattern matches far more than expected, a greedy quantifier is the first thing to check. A negated class such as <[^>]+> is often both clearer and faster than a lazy dot.

Anchors, lines and the dot

By default ^ and $ match only at the very start and end of the whole text. Tick the multiline flag and they match at each line boundary, so ^error finds every line that begins with error. The dot normally skips line breaks; the dot-matches-newlines flag lets it cross them, which is what you want when a pattern must span several lines.

These two flags are independent, and mixing up which one does what accounts for many patterns that work on one line of text but fail on a pasted block.

Why the Unicode flag matters

Without the u flag, \w means only the ASCII letters, digits and underscore. Run \w+ on Café and you get Caf, because the accented letter is not a word character. With the u flag you can use property escapes, and [\p{L}]+ matches the whole word Café.

The flag also makes emoji and other characters outside the basic range count as single characters instead of two halves. If your text includes Bangla, accented European letters or emoji, turn it on early.

What the tester cannot tell you

It follows JavaScript rules, so it shows you what browsers and Node will do. Other languages differ in details such as inline flags, possessive quantifiers and the way named groups are written. Test in the real environment before you rely on a pattern for security checks.

The table shows captured groups by number, and the highlight skips empty matches, so a pattern that matches nothing visible may still be producing empty hits. Output is capped at 1,000 matches, and a pattern that takes longer than 1.5 seconds is stopped with a message instead of freezing the page.

Questions

Is my text sent to a server?

No. Matching runs in your browser.

Why does my pattern show an error?

The pattern is not valid in JavaScript. The message under the box says what is wrong, such as an unclosed bracket.

How many matches does it show?

It lists up to the first 1,000 matches and shows the first 200 in the table.

What does an empty match mean?

The pattern matched at a position without taking any characters, which can happen with patterns like a*.

Why does my replacement only change the first match?

The global flag is off. Without g, the pattern is applied once, and so is the replacement. Tick g to replace every match.

How do I match a literal dot, bracket or question mark?

Put a backslash before it, for example \. or \?. Inside a character class most of these lose their special meaning.

Why does the same pattern work in my code but not here?

Check that the flags match, that you did not forget to escape a backslash when writing it inside a string literal in code, and that your language uses the same regex dialect as JavaScript.

Can I use named groups?

Named groups in the pattern are valid JavaScript and will match, and you can refer to them in the replacement as $<name>. The table lists captured groups by position.

What does the timeout message mean?

The pattern is probably backtracking heavily, as nested quantifiers like (a+)+ do on a long run of a. Rewrite it to avoid ambiguous repetition.