# Regex Tester

Type a pattern and matches light up in the test string instantly. Capture groups, replacement output and what each part of the pattern means are all on one screen — and patterns that would freeze your browser are stopped after one second.

- URL: https://tools.itlibra.com/en/regex-tester
- On-device・No upload
- Last updated: 2026-10-26

## How to use

1. Enter the pattern (the part between the slashes, e.g. \\d{3}-\\d{4}) and toggle flags such as g, i and m.
2. Paste the text to search into “Test string”. Matches are highlighted in place, and the panel on the right lists each match’s index, length and groups.
3. To replace, switch to “Replace” and enter a replacement using $1 or $\<name\>; the output shows exactly what changed.
4. For validation patterns, use “Test cases”: list values that should and should not match, one per line, and see pass/fail for all of them.
5. Copy the finished pattern as a “JS literal” or as “new RegExp()” and paste it into your code.

## Use cases

- Validate a form-validation regex (email, postal code, phone number) against good and bad examples
- See how many matches a pattern finds in logs or CSV — and where — before extracting data
- Preview a $1 / $\<name\> search-and-replace before running it in your editor or script
- Decode a complex regex written by someone else, piece by piece
- Safely reproduce whether a production hang was caused by a regex (ReDoS)

## What it does

### Live in-place highlighting

Matches are painted directly on the test string as you type. Adjacent matches alternate colours and zero-width matches show as a thin bar, so you see exactly where — and how often — the pattern hits. Pick a match in the list to select it in the text.

### Numbered and named groups

Every match lists $1, $2… and named groups (?\<name\>…) with their values and positions. Groups that did not participate and empty strings are shown distinctly, which makes backreferences and replacements easy to build.

### Replace preview with a change list

$1, $\<name\>, $&, $\` and $' are expanded exactly as the JavaScript spec defines, and the output highlights what changed. A before → after list is included; copy or save the result.

### Pass/fail test cases

Check a validation regex against “should match” and “should not match” lists in one go. Optionally require a whole-line match (wrapping in ^…$); a bar shows how many cases pass.

### Pattern explained in plain language

Our own parser explains quantifiers, character classes, lookarounds, backreferences and Unicode properties one token at a time. Syntax errors point to the exact character and suggest a fix.

### Built not to freeze your browser

Matching runs in a Web Worker and is terminated after one second. Classic catastrophic-backtracking shapes like (a+)+ are flagged up front with tips to fix them.


## Supported formats

### Syntax

- JavaScript (ECMAScript 2025) RegExp
- Flags d, g, i, m, s, u, v, y
- Named groups & backreferences
- Lookahead & lookbehind
- Unicode properties \\p{…}

### Copy as

- JS literal /…/flags
- new RegExp("…", "flags")
- Replacement output (text file)
- Split result (JSON)


## Capability matrix

| Feature | Support | Notes |
| --- | --- | --- |
| Match highlighting, positions & groups | Supported | Up to 10,000 matches listed; first 2,000 highlighted |
| Replace preview ($1, $\<name\>, $& …) | Supported | Identical to String.prototype.replace |
| Split and multi-line pass/fail testing | Supported | — |
| Pattern explanation & error position | Partial | Common syntax covered; v-flag set operations are shown as raw items |
| Catastrophic backtracking detection | Partial | 1-second hard stop plus warnings for classic shapes; not every dangerous pattern can be predicted |
| PCRE, Python, Java or .NET regex flavours | Not supported | Runs on the JavaScript engine; (?i), \\A, possessive quantifiers etc. behave differently |
| Saving patterns or share links | Not supported | Nothing you type is stored anywhere |
| Offline use | Supported | Works without a connection once loaded |

## Limits & notes

- Test strings up to 1,000,000 characters; patterns up to 10,000 characters.
- Up to 10,000 matches are counted and listed; the rest are cut off (replacement output is still computed in full).
- Above 200,000 characters, in-place highlighting is turned off and only the list is shown.
- Any single run longer than one second is stopped. Split very large inputs if a legitimate pattern is slow.
- Available flags and syntax depend on your browser’s JavaScript engine (the v flag needs a recent browser).

## Privacy & safety

Your pattern and test text are processed only inside your browser. Nothing is uploaded or stored, and analytics never include what you type — so it is safe to test against logs or customer data.

## FAQ

### How do I match Japanese or other non-Latin text?

Turn on the u flag and use Unicode properties such as \\p{Script=Han} for kanji or \\p{L} for any letter; ranges like \[ぁ-ゖ\] (hiragana) and \[ァ-ヶー\] (katakana) also work. Note that \\d and \\w only match ASCII digits and letters.

### Is there a perfect email regex?

No. Fully implementing RFC 5322 is impractically complex, and no regex can tell whether an address exists. The library here uses the same pragmatic rule as the browser’s \<input type="email"\> and states its limits.

### What is ReDoS / catastrophic backtracking?

Patterns with nested repetition such as (a+)+$ can try an exponential number of combinations on input that almost matches, freezing the program. This tool runs matching in a separate thread and stops it after one second, so you can reproduce the problem safely.

### What is the difference between $1 and $\<name\> in a replacement?

$1 inserts the first parenthesised group; $\<name\> inserts the group declared as (?\<name\>…). Named groups keep working when you add more groups. $& is the whole match and $$ is a literal dollar sign.

### What happens without the g flag?

Only the first match is found, and Replace changes only the first occurrence. Turn on g to target every match, and m if ^ and $ should apply to each line.

### Can I test Python or PHP regular expressions?

Patterns are evaluated by your browser’s JavaScript engine. The basics are shared, but inline flags like (?i), \\A / \\Z and possessive quantifiers differ, so double-check in the target language.
