# Regex Tester

> The Regex Tester runs your JavaScript regular expression against sample text as you type, highlights every match, lists capture groups, supports all flags and a replace mode, and includes a cheat sheet and common patterns.

URL: https://atechcraft.com/regex-tester/
Category: Developer Tools
Last updated: 2026-12-01
Author: Abdul Moid Khan, ATechCraft

Runs in your browser. Your data never leaves your device.

## How to use the Regex Tester

1. Type a pattern and choose flags (g, i, m, s, u, y).
2. Paste test text. Matches are highlighted instantly.
3. Check the groups table for capture group values.
4. Switch on replace mode to preview a replacement string with $1 and named groups.

## What is a regex tester?

A regex tester lets you try a regular expression (regex) against sample text and see what it matches before you use it in code. This tester highlights every match as you type, lists capture groups in a table, supports all JavaScript flags, has a replace mode with `$1` and named groups, and includes a cheat sheet and a library of common patterns.

A regular expression is a small pattern language for finding text. For example, `\d{4}-\d{2}-\d{2}` finds dates like 2026-12-01.

## How does the regex tester work?

It uses your browser's own JavaScript regular expression engine, the same one that runs your code in Chrome, Firefox, Safari or Node.js. The syntax follows the ECMAScript standard, documented clearly on [MDN's regular expressions guide](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions).

When you type, the tool:

1. Builds a `RegExp` from your pattern and flags. If that fails, it shows the browser's error message.
2. Runs `matchAll` (or a single `match` without the `g` flag) on your text.
3. Highlights each match and fills the groups table with each match's position and captured groups.

It shows up to 1,000 matches so a pattern that matches every character can't freeze the page.

## What do the flags do?

| Flag | Name | Effect |
| --- | --- | --- |
| `g` | global | Find all matches, not just the first |
| `i` | ignore case | `a` matches `A` |
| `m` | multiline | `^` and `$` match at the start and end of each line |
| `s` | dotAll | `.` also matches newline characters |
| `u` | unicode | Treats emoji and other astral characters as one character; enables `\p{…}` classes |
| `y` | sticky | Matches only at the current position |

Use `u` whenever your text may contain Urdu, Arabic or emoji and you use classes like `\p{L}` (any letter in any language).

## Worked example

Pattern: `\b(\w+)@(\w+)\.com\b` with flag `g`
Text: `Contact ali@example.com or sara@test.com for help.`

Results: **2 matches**.

| # | Match | Index | Group 1 | Group 2 |
| --- | --- | --- | --- | --- |
| 1 | ali@example.com | 8 | ali | example |
| 2 | sara@test.com | 27 | sara | test |

Turn on replace mode with `$1 at $2` and the result is `Contact ali at example or sara at test for help.` With named groups, `(?<user>\w+)@(?<site>\w+)\.com`, the replacement can be written `$<user> at $<site>`, which is easier to read later.

## Tips

1. **Start simple and grow.** Match a fixed word first, then add classes and quantifiers one at a time.
2. **Escape special characters** like `. ? + * ( ) [ ] { } | \ ^ $` with a backslash when you mean them literally. A plain `.` in `example.com` matches any character.
3. **Use anchors and boundaries.** `\b` stops `cat` matching inside `category`.
4. **Avoid catastrophic backtracking.** Nested quantifiers like `(a+)+$` can take exponential time on text that almost matches. Make inner parts more specific.
5. **Don't parse HTML or JSON with regex.** Use the [JSON Formatter](https://atechcraft.com/json-formatter/) for JSON, and real parsers for HTML.
6. **Compare before and after** a replace with the [Text Diff Checker](https://atechcraft.com/text-diff/).
7. **Writing Apache redirect rules?** Test the path pattern here, then generate the rule with the [.htaccess Redirect Generator](https://atechcraft.com/htaccess-redirect-generator/).

## Limitations

- This is the **JavaScript** flavour. Most syntax is shared with PCRE (PHP), Python and Java, but features like possessive quantifiers (`a++`), atomic groups and `\A`/`\Z` anchors don't exist in JavaScript, and lookbehind support varies in older browsers.
- The common patterns are practical starting points, not perfect validators. The email pattern, for example, accepts most real addresses but not every address the email standard allows.
- Very slow patterns can still pause the page briefly before results appear.

For scheduling patterns rather than text patterns, see the [Cron Expression Builder](https://atechcraft.com/cron-builder/).

## Frequently asked questions

### Which regex flavour does it use?

Your browser’s JavaScript (ECMAScript) engine. Most syntax matches PCRE and Python, but some features, such as possessive quantifiers, differ.

### Why do I only get one match?

Add the g (global) flag to find all matches instead of the first one.

### What do the m and s flags do?

m makes ^ and $ match at each line break. s lets the dot match newline characters too.

### Can a regex freeze the page?

Patterns with nested quantifiers, such as (a+)+, can take exponential time on some inputs. The tester limits the number of matches it shows to stay responsive.
