Free · No sign-up · Private

Regex Tester

Use this free regex tester to test regular expressions (regex) right in your browser — type a pattern, paste some text, and see every match highlighted instantly, with the match count, positions and capture groups. Switch flags on and off, try a ready-made pattern for email, URL, phone or CNIC, and test replacements with $1, $2 and the other group references. Everything runs in your browser: nothing is uploaded or stored.

Regex Tester

Test regex patterns live — matches, groups & replace.

Matches

Positions are character positions in your text — first character is 0.

—

Private by design: every test runs in your browser — nothing is uploaded or stored.

How to use the Regex Tester

  1. Type your regular expression in the Pattern box — or tap a ready-made pattern below, for example Email or Pakistani mobile number.
  2. Paste or type the text to test in the Test text box. Matches are highlighted as you type, with the total match count underneath.
  3. Tick the flags you need: g for all matches, i to ignore upper and lower case, m for multi-line text, s so a dot matches line breaks, and u for full Unicode.
  4. To try a replacement, type the replacement text (use $1, $2 for capture groups) and click “Replace all” — the replaced text appears below, ready to copy.

What is a Regular Expression?

A regular expression — usually called regex or regexp — is a pattern that describes a set of text. Instead of searching for one exact word, you describe the shape of what you want: \d+ means “one or more digits”, [A-Z][a-z]+ means “a capital letter followed by small letters”, and [\w.-]+@[\w.-]+\.\w+ means “something shaped like an email address”. Developers use regex every day to check form inputs, pull values out of logs and files, and find and replace text in code. It is one of the most useful skills in programming, and also one of the most searched-for topics — because a regex that is almost right can be hard to debug, and the only reliable way to get it right is to test it against real text and watch what it matches.

How to test a regex with this tool

Testing takes four steps. Step 1: type your pattern in the Pattern box, or tap one of the ready-made patterns below — email, website URL, Pakistani mobile number, CNIC, date, hex colour, digits or capitalised words. Step 2: paste or type the text to test. The sample text is already filled in, so the default email pattern shows two matches the moment the page loads. Step 3: tick the flags you need — g to find every match, i to ignore upper and lower case, m for multi-line text, s so a dot matches line breaks, and u for full Unicode. Step 4: read the result — the match count, the highlighted text, and the match list with the character position of every match (first character is 0) and the capture groups inside it. If the pattern has a mistake, the tool shows the exact error message instead of guessing.

Common regex patterns

A few patterns cover most everyday jobs. An email address is [\w.-]+@[\w.-]+\.\w+ — word characters, dots and hyphens, then @, then the domain. A Pakistani mobile number is (?:\+92\s?|0)3\d{2}[- ]?\d{7} — +92 or 0, then a 3, then two digits, an optional space or hyphen, then seven digits — it matches both 0300-1234567 and +92 300 1234567. A CNIC number is \d{5}-\d{7}-\d — five digits, a hyphen, seven digits, a hyphen, one digit. A date in YYYY-MM-DD form is \d{4}-\d{2}-\d{2}. A hex colour is #[0-9a-fA-F]{6} — a # followed by six hexadecimal digits, like #FFD700. And \d+ on its own simply finds every run of digits in the text.

Capture groups and replacement

Round brackets ( ) create a capture group — a part of the match you can reuse. In (\w+)@(\w+), group 1 is the name before the @ and group 2 is the domain after it, and this tester lists both groups under every match. Groups are what make replacement powerful: with the pattern (\d{4})-(\d{2})-(\d{2}) and the replacement $3/$2/$1, the date 2026-11-17 becomes 17/11/2026 — the year, month and day are simply reordered. Try it here first: type the replacement, click “Replace all”, and check the result before you use the pattern in your own code.

Example

Take the sample text on this page and the default email pattern [\w.-]+@[\w.-]+\.\w+. The tester finds 2 matches: hello@example.com at character position 14 and support@toolkamai.com at character position 35. Now tap the “Pakistani mobile” chip: the pattern changes to (?:\+92\s?|0)3\d{2}[- ]?\d{7} and the tester finds 2 matches — 0300-1234567 and +92 300 1234567. Tap “Digits only” and it finds 14 runs of digits, from 0300 and 1234567 to 2026, 11 and 17. And if you type [ as a pattern, the tester does not crash — it shows “Invalid regular expression: Unterminated character class” and tells you exactly what is wrong.

Tips and common mistakes

  • Escape the dot. In regex a plain . means “any character” — so example.com as a pattern also matches exampleXcom. Use \. when you mean a real full stop.
  • Remember the g flag. Without g, the tester stops at the first match — which is correct for a single check, but misleading when you want to count or replace every match.
  • Use ^ and $ carefully. They mean the start and end of the whole text unless you tick the m flag, which makes them match the start and end of each line.
  • Watch out for greedy matching. .* grabs as much as it can — so “.*” on “a” and “b” matches the whole line, not just “a”. Use .*? (lazy) when you want the shortest match.
  • Test with real text, not just the happy path. A pattern that matches your example may also match things it should not — paste messy, real-world text and check the highlighted matches one by one.
Tip: Building a form? Test your email, phone and CNIC patterns here first, then copy the exact pattern into your form validation — a pattern tested against real text is worth more than one copied from a tutorial.

When to test a regex

Use it before a pattern goes anywhere near real data. A form that checks email addresses, a script that pulls phone numbers out of a spreadsheet, a search-and-replace across a hundred files — in each case a wrong pattern either misses good data or catches bad data, and both are expensive. Test with five examples that should match and five that should not, try the ready-made patterns for email, URL, phone and CNIC, and check the capture groups before you use a replacement. A pattern tested here behaves exactly the same in your JavaScript code, because the tester uses your browser's own regex engine.

Learn more: Read the guide: Regex Tester Guide — Learn Regular Expressions →

Frequently asked questions

What is regex?

A regular expression (regex) is a pattern that describes text — for example \d+ means “one or more digits” and [A-Z][a-z]+ means “a capital letter followed by small letters”. Developers use regex to check emails and phone numbers, find and replace text, and pull values out of logs and forms. This tester lets you try a pattern and see exactly what it matches, before you use it in code.

Is this regex tester really free?

Yes, 100% free, no sign-up, no limits. It runs entirely in your browser — test as many patterns as you like.

Why does my pattern show “Invalid regular expression”?

The pattern has a mistake in its syntax — for example an unclosed bracket [ or a stray backslash at the end. The error message under the pattern box explains what is wrong; fix that part and the matches appear again. Common mistakes: forgetting to escape a dot (use \. for a real full stop) and leaving a ( group unclosed.

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

g (global) finds every match instead of stopping at the first one. i (ignore case) treats A and a as the same. m (multiline) makes ^ and $ match the start and end of each line, not just the whole text. s (dotAll) lets a dot match line breaks too. u (unicode) makes the pattern handle emoji and non-English letters correctly. Most testers keep g on and add i when case does not matter.

Can I test a regex with capture groups?

Yes — round brackets ( ) create capture groups, and the match list shows every group under its match. For example, in (\w+)@(\w+) group 1 is the name before the @ and group 2 is the domain after it. You can reuse groups in a replacement with $1, $2 and so on — so (\d{4})-(\d{2})-(\d{2}) replaced with $3/$2/$1 turns 2026-11-17 into 17/11/2026.

Does the tester support lookahead, lookbehind and other advanced regex?

Yes — it uses your browser's own JavaScript regex engine, so lookahead (?=...), negative lookahead (?!...), lookbehind (?<=...) and (?

Copied!