# Regex Tester

> Test regular expressions live: highlighted matches, numbered and named groups, flag switches, find and replace, and clear errors. Free and private.

Canonical: https://cromagnon.app/tools/regex-tester
Last updated: 2026-10-26

- Category: Developer
- Formats: TEXT
- Use it: https://cromagnon.app/tools/regex-tester (free, runs in the browser)

## What it does

Write a regular expression, paste your text and see every match highlighted as you type, with numbered and named capture groups for each one. Switch flags on and off, try a replacement with $1 and $<name>, and get a warning when a pattern could freeze the page. The tool can also ask AI to write or explain a pattern.

## How to use it

1. Type the pattern, or paste a literal like /\d+/g and the flags are picked up automatically.
2. Tick the flags you need: g, i, m, s, u or y.
3. Paste the test text. Matches are highlighted and listed with their position and groups.
4. Optionally tick Replace matches and type a replacement to see the result of a find and replace, then copy it. Leave the replacement empty to delete every match.

Tip: Every match is listed even without the g flag, but your code behaves differently: without g, String.match and replace stop at the first match. The tool shows a reminder when that applies.

## Regex cheat sheet

- **. \d \w \s**: Any character (except a line break), a digit, a word character (letter, digit, _), a whitespace character. Capitals mean the opposite: \D is anything but a digit.
- **[abc] [^abc] [a-z]**: One character from the set, one not in the set, one in the range.
- *** + ? {2,5}**: Repeat: zero or more, one or more, zero or one, between 2 and 5 times. Add ? (as in +?) to match as little as possible.
- **^ $ \b**: Start and end of the text (or of each line with m), and a word boundary.
- **( ) (?: ) (?<name> )**: A numbered group, a group that isn't captured, and a named group.
- **a|b**: Either a or b.
- **(?= ) (?! ) (?<= ) (?<! )**: Lookahead and lookbehind: check what comes next or before without including it in the match.
- **\1 \k<name>**: Match the same text a group matched earlier, for example (\w)\1 for double letters.

## The flags

- **g (global)**: Find every match, not only the first.
- **i (ignore case)**: A matches a.
- **m (multi-line)**: ^ and $ match at the start and end of each line.
- **s (dot all)**: . also matches line breaks.
- **u (Unicode)**: Treat emoji and other characters outside the basic range as one character, and allow \p{L} for any letter in any language.
- **y (sticky)**: Each match must start exactly where the last one ended.

## Patterns you can copy

- **Email (simple)**: [\w.+-]+@[\w-]+\.[\w.-]+ finds most email addresses. No regex catches every valid address; send a confirmation email if it must be right.
- **Date (2026-10-26)**: \d{4}-\d{2}-\d{2}, or with named groups (?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2}).
- **Hex colour**: #(?:[0-9a-fA-F]{3}){1,2}\b
- **Repeated words**: \b(\w+)\s+\1\b finds “the the” typos (use the i flag too).
- **Trailing spaces**: [ \t]+$ with the g and m flags; tick Replace matches and leave the replacement empty.

## Find and replace with groups

In the replacement, $1 and $2 insert numbered groups, $<name> a named group, $& the whole match and $$ a dollar sign. \n and \t insert a line break and a tab. For example, the pattern (\w+), (\w+) with the replacement $2 $1 turns “Doe, Jane” into “Jane Doe”.

Swapping a date from 2026-10-26 to 26/10/2026 works the same way: (\d{4})-(\d{2})-(\d{2}) and $3/$2/$1.

## Why some patterns freeze the page

Nested repeats such as (a+)+ or (\w*)* can make the regex engine try an enormous number of ways to match, a problem called catastrophic backtracking. On text that almost matches, it can take minutes. The tool warns you when it sees this shape. Make the inner part more specific, or remove the outer repeat.

## Greedy vs lazy matching

By default, * and + take as much text as they can and then give back only what they must. In <b>one</b> and <b>two</b>, the pattern <b>.*</b> matches everything from the first <b> to the last </b>. Add a question mark, <b>.*?</b>, and each bold part becomes its own match. When a match is longer than you expected, a greedy repeat is usually the reason.

## Tips

- **Escape special characters**: To match . * + ? ( ) [ ] { } ^ $ | \ or / literally, put a backslash in front: \. matches a full stop.
- **Lazy beats greedy for tags**: <.+?> matches one HTML tag; <.+> would run to the last > on the line.
- **Anchor validation patterns**: Use ^ and $ around a pattern when the whole input must match, not just part of it.
- **Name your groups**: (?<year>\d{4}) is easier to read and reuse than counting brackets.

## Questions

### Which regex flavour does this use?

JavaScript's, the same as in browsers and Node.js. Most patterns work the same in Python, PHP, Java and .NET; lookbehind and named groups are written the same way in most of them.

### Why does my pattern match an empty string?

Patterns that can match nothing, like \d*, also match between characters. Use + instead of * if at least one character is needed. Empty matches are listed but not highlighted.

### Can I paste a regex from my code?

Yes. Paste /pattern/flags and the tool splits it into the pattern and flags for you.

### Why do I only see 1,000 matches?

The list stops at 1,000 matches so the page stays fast; the count shows that there are more.

### Is the AI explanation private?

The pattern and test text are sent to the AI provider only when you press the AI buttons and have set up your own key. Testing a pattern never sends anything.

### How do I match a whole word only?

Put \b on both sides: \bcat\b matches cat but not category or concat.

### Is anything I type uploaded?

No. The tool runs in your browser; what you type or paste never leaves your device and nothing is stored on a server.

## Related

- [Text Extractor](https://cromagnon.app/tools/text-extractor)
- [Line Sorter](https://cromagnon.app/tools/line-sorter)
- [JSON Formatter](https://cromagnon.app/tools/json-formatter)
- [Case Converter](https://cromagnon.app/tools/case-converter)
- [All tools](https://cromagnon.app/tools)
