Skip to the content

Contact usFree tools · No signup · Files stay on your device

Developer Tools

Regex Tester: the complete guide to testing regular expressions

Regex Tester: the complete guide to testing regular expressions

A regular expression, or regex, is a short pattern that describes text: "an 11-digit mobile number starting with 01", "a date like 2026-10-09", "anything between two tags". They are powerful and easy to get wrong, which is why you test them on real text before you put them in code. Our free Regex Tester shows every match highlighted as you type, lists capture groups, previews a replacement, and stops patterns that run away.

This guide goes through every part of the page, a few worked examples with Bangladeshi data, and the problems that trip up most beginners.

What Regex Tester does

You enter a pattern, switch flags on or off and paste some test text. The tool searches the text with your browser's own JavaScript regex engine, so the result matches what new RegExp() and String.replace do in Chrome, Firefox, Safari and Node.js. It then shows:

  • Every match highlighted in the text.
  • A count of matches and how long the search took.
  • A table with the position of each match and its groups.
  • The text after a replacement.

It tests JavaScript regular expressions only. Other languages, such as Python or PHP, share most of the syntax but differ in places, so check the details before you copy a complex pattern across.

How to use Regex Tester, step by step

  1. Open Regex Tester. It starts with the Date (named groups) example already loaded.
  2. Type your pattern in the box between the two slashes. Do not type the slashes or the flags.
  3. Click the flag buttons you need: g, i, m, s, u, y or d.
  4. Paste your text into the Test string panel, in the box labelled "Text to search".
  5. Read the Matches highlighted panel and the status line above it, such as "2 matches".
  6. Open Match details to see where each match is and what each group captured.
  7. In the Replace panel, type a replacement to see the changed text, and press Copy.
  8. Press Copy as /regex/ at the top of the Pattern panel to copy the finished pattern with its flags for your code.

You can also load a ready-made case with the Email, URL, IPv4, Date (named groups) or Backtracking demo buttons.

Every option explained

The seven flags

Each button shows the flag letter and a short name. Hover over one to see its full description.

Flag Name What it changes
g global Finds all matches. Without it, only the first match is found and only the first is replaced.
i ignore case rahim also matches Rahim and RAHIM.
m multiline ^ and $ match at the start and end of every line, not just of the whole text.
s dotAll . also matches line breaks.
u unicode Works with full characters and enables classes such as \p{L}.
y sticky Matches only at the exact position where the search starts.
d indices Asks the engine to record group positions. The tester does not show extra detail for it.

When g is off and the pattern matches, a hint reminds you: "Only the first match is shown — turn on the g flag to find all."

Matches highlighted

The matches are marked in the text, and neighbouring matches alternate between two colours so you can see where one ends and the next begins. A match with no length, such as the one a* finds before a b, is drawn as a thin red mark with a tooltip "Empty match at" and its position.

Match details

A table with four columns: #, Index, Match and Groups. Index is written as start–end, counting from 0. The Groups column lists $1, $2 and so on with the captured text in quotes, followed by the named groups in angle brackets. A group that did not take part in the match shows "(did not match)" in grey. The table shows the first 500 matches.

Replace

Type what each match should become. Use $1, $2 for numbered groups, $<name> for named ones, $& for the whole match and $$ for a literal dollar sign. The replaced text appears below and has its own Copy button. The same flags apply, so without g only the first match changes. An empty box replaces matches with nothing, which is a handy way to delete them.

Regex quick reference

Under the panels, a collapsible reference lists the common pieces in six groups: Characters, Sets & anchors, Quantifiers, Groups, Lookaround and Replacement. Open it when you cannot remember whether a lazy quantifier is *? or ?*.

What it accepts and its limits

  • Pattern: any pattern your browser accepts. A bad pattern shows "Invalid regular expression:" followed by your browser's own explanation, so the wording differs a little between browsers.
  • Matches: at most 5,000 are counted. After that the count shows a plus sign and the page says "Stopped after 5,000 matches."
  • Match details: the first 500 rows. A line says how many more there are.
  • Time: a search that takes more than 1.5 seconds is stopped.
  • Highlighting: drawn only when the result matches the text now in the box, so you never see old highlights on new text.

Privacy

The searching runs in your browser, inside a background worker. Your pattern and your test text are not sent to a server, so you can test patterns on logs, customer lists and other private text. The page does not store them either.

Worked examples

Bangladeshi mobile numbers

Test text:

Call 01712345678 or 01812345678, +8801912345678. Wrong: 01212345678 and 0171234567.

Pattern, with g on:

\b01[3-9]\d{8}\b

The tester finds two matches: 01712345678 and 01812345678. It rejects 01212345678 because the third digit must be 3 to 9, and 0171234567 because it has only ten digits. It also skips +8801912345678, because the \b before 01 needs a word boundary, and the 88 before it is a word character. To accept the country code, make it optional:

(?:\+?88)?01[3-9]\d{8}\b

Now all three real numbers match, including the one written with +88.

To mask numbers, use groups and a replacement. Pattern \b(01[3-9]\d)\d{4}(\d{3})\b with replacement $1****$2 turns 01712345678 into 0171****678.

Dates with named groups

The built-in example is (?<year>\d{4})-(?<month>0[1-9]|1[0-2])-(?<day>0[1-9]|[12]\d|3[01]). On "Released 2026-10-09, patched 2026-11-23." it finds two dates, at 9–19 and 29–39, and each one lists year, month and day in the Groups column. With the replacement $<day>/$<month>/$<year> the text reads "Released 09/10/2026, patched 23/11/2026." The impossible date 2026-13-01 in the example is not matched, because 13 is not a month.

Greedy and lazy matching

On <b>Dhaka</b> and <b>Sylhet</b>, the pattern <b>.*</b> finds one match that covers the whole line, because .* takes as much as it can. Add a question mark, <b>.*?</b>, and you get two matches, one per tag. If a pattern grabs too much, look for a greedy * or + and try the lazy version.

Tips to work faster

  • Start with plain text and a small test, then add one piece at a time. When the highlight changes, you know which piece did it.
  • Put real examples of both good and bad input in the Test string panel, as in the phone number example, so you see failures as well as matches.
  • To check every line of a list separately, turn on m and use ^ and $. ^\d+$ on the lines 101, abc and 2026 finds nothing without m and finds 101 and 2026 with it.
  • Trim spaces at both ends of a text with the pattern ^\s+|\s+$, g on and an empty Replacement.
  • For letters in any script, use u and [\p{L}\p{M}]+. Plain \w ignores Bangla altogether, and \p{L}+ alone splits Bangla words at their vowel signs.
  • Use Text Diff Checker to compare the original and the replaced text, and the Case Converter when the job is only about letter case.

Common problems and how to fix them

"Pattern took too long"

The tester stops after 1.5 seconds and explains that this usually means catastrophic backtracking. It happens when a repeated group can match the same text in many ways, as in (a+)+, and the text almost matches. Click the Backtracking demo button to see it: the pattern ^(a+)+$ fails on a long run of a followed by an exclamation mark. Make the inner part more specific, or use a negated class such as [^,]* instead of .*. You can read more in the guide to email validation patterns, where this danger is common.

"Invalid regular expression: …"

The pattern has a syntax error, such as an unclosed bracket or group. The message comes from your browser, so the wording varies. Look for a missing ), ] or }, or a lone \ at the end.

Only one match is found

The g flag is off. Turn it on.

^ and $ do not work line by line

Without the m flag, they match only at the start and end of the entire text. Turn m on.

The dot does not match a line break

By default, . stops at a line break. Turn on s if you want it to cross lines, or use [\s\S] in the pattern.

The same pattern behaves differently in my program

Check the flags first, because the page and your code must use the same ones. After that, look at the language: lookbehind support, named group syntax and escape rules vary. The tester shows what JavaScript does.

A match of zero length

A pattern that can match nothing, such as a*, matches the empty space between letters. They show as thin red marks and as "(empty)" in the details table. Use + instead of * when you need at least one character.

Quick checklist

  • Type the pattern without slashes and set the flags with the buttons.
  • Test good and bad examples together.
  • g for all matches, m for lines, i for case, u for other scripts.
  • Replacement with $1 or $<name>, and $& for the whole match.
  • Avoid nested repeats, and treat "Pattern took too long" as a warning.

Frequently asked questions

Do I type the slashes and flags in the pattern box?
No. The slashes are drawn around the box for you, and the flags are switched on with the buttons below it. If you type /abc/gi into the box, the slashes become part of the pattern and nothing will match as you expect. Use Copy as /regex/ when you want the complete literal for your code.
Why does \w not match Bangla letters?
In JavaScript, \w means only A to Z, a to z, 0 to 9 and the underscore. For Bangla, turn on the u flag and use [\p{L}\p{M}]+. The \p{M} part is needed because vowel signs are marks, not letters, so \p{L} alone breaks a word into pieces.
What does an empty Replacement box do?
It replaces each match with nothing, which deletes it. Because the replace step uses your flags, the same pattern with g removes every match, and without g it removes only the first one.
Why is there a limit of 5,000 matches?
A pattern such as an empty match or a single letter can match millions of times in a long text, which would freeze the page. The tester stops at 5,000 matches, shows a plus sign after the count and says so. The details table shows the first 500.
Why can the highlighting trail behind my typing?
The tester waits about 0.15 seconds after your last keystroke before it searches, and it only draws the highlights when the result belongs to the text currently in the box. The status line shows Running… while it works.
Found this useful? Share it

Tools in this guide

Main tool

Regex Tester

Write a regular expression and see every match highlighted as you type, with capture groups, named groups and a live replace preview.

Open tool

Text Diff Checker

Paste or open two versions of a text and see exactly what changed: added lines in green, removed lines in red.

Open tool

JSON Validator

Check whether your JSON is valid and get the exact line, column and reason for any error.

Open tool

Case Converter

Change the case of any text in one click — from headline-style Title Case to programmer formats like camelCase and snake_case.

Open tool

Back to all guides & blog