# Regex Tester

> One page from jmrp.io, published as markdown. Index: https://jmrp.io/llms.txt

Canonical: https://jmrp.io/tools/regex-tester/
Language: en
Alternate: https://jmrp.io/es/tools/regex-tester/index.md
Updated: 2026-08-25
License: https://jmrp.io/license/
Category: developer
Tags: regex, regexp, pattern, grep, sed, testing

Test regular expressions with real-time match highlighting, capture groups, replace mode, and common pattern presets. Runs in your browser.
Build-Date: 2026-09-06

Features:
- Real-time match highlighting as you type
- Named and numbered capture groups
- Replace mode with backreferences
- Toggleable g/i/m/s/u flags and presets
- Runs locally in your browser

Questions answered:

**Are my regex patterns and test strings sent to a server?**

No. All pattern matching and text processing runs entirely in your browser using JavaScript's built-in RegExp engine. Your patterns and test strings never leave your device.

**Which regex flavor does this tester use?**

It uses JavaScript's native RegExp engine, which follows the ECMAScript specification. Patterns may behave differently in PCRE, Python, or POSIX tools, so check the flavor comparison table before porting them.

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

g finds all matches instead of just the first, i makes matching case-insensitive, m makes ^ and $ match the start/end of each line, s lets . match newlines, and u enables full Unicode matching and property escapes.

**How do I test a find-and-replace?**

Toggle Replace Mode and enter a replacement string. You can reference captured groups with $1, the whole match with $&, and named groups with $<name>.

**Why does my pattern hang or take a long time?**

Patterns like (a+)+b cause catastrophic backtracking on long non-matching input. The tool shows the execution time for each test, so if a pattern takes more than a few milliseconds, simplify it or use negated character classes instead of greedy wildcards.


---

**Interactive tool** — this page hosts the working application itself, not a description of one.

## About This Tool

A real-time regex tester that highlights matches, extracts capture groups
(named and numbered), supports find-and-replace with backreferences, and
provides quick access to common patterns used in web development and system
administration.

### Features

- **Real-time highlighting** — matches highlighted with alternating colors as you type
- **Capture groups** — both named (`(?<name>...)`) and numbered groups displayed with labels
- **Replace mode** — test substitutions with backreferences ( `$1`, `$&`,`$<name>`)
- **Regex flags** — toggle global, case-insensitive, multiline, dot-all, and unicode
- **10 pattern presets** — email, URL, IPv4, UUID, phone, JWT, MAC address, HEX color, ISO date, and Nginx location
- **Match statistics** — count, execution time, and line:column position for every match
- **Quick reference** — collapsible regex cheat sheet with characters, anchors, quantifiers, groups, and lookaround

### How Do I Use It?

1. Enter your regex pattern in the pattern field
2. Set the desired flags (g, i, m, s, u) using the checkboxes
3. Type or paste your test string in the textarea
4. Matches are highlighted in real time with detailed info below
5. Toggle **Replace Mode** to test substitutions — enter a replacement string with `$1`, `$&`, or `$<name>` backreferences
6. Click any **preset** to load a common pattern with matching sample text
7. Expand **Quick Reference** at the bottom for a compact regex syntax cheat sheet

### What Do the Regex Flags Do?

Flags (also called modifiers) change how the regex engine interprets your pattern. In JavaScript they are placed after the closing delimiter: `/pattern/flags`. This tool lets you toggle each one individually.

g

**Global**

Find *all* matches in the string instead of stopping after the first one. Without `g`, only the first match is returned. Essential when counting occurrences or performing a global find-and-replace.

`/\d+/g` on `"a1 b2 c3"` → 3 matches ( `1`, `2`, `3`)

i

**Case-Insensitive**

Makes the pattern match regardless of letter case. `/abc/i` matches `abc`, `ABC`, `aBc`, etc. Applies to both literal characters and character ranges like `[a-z]`.

`/error/i` matches `"Error"`,`"ERROR"`, `"error"`

m

**Multiline**

Changes the behavior of `^` and `$` anchors. Normally they match the start/end of the entire string. With `m`, they match the start/end of each *line* (separated by `\n`). Does not affect `.` — use `s` for that.

`/^server/m` matches `"server"` at the start of any line, not just the first

s

**Dot-All (Single-line)**

Makes the `.` metacharacter match *any* character including newlines (`\n`,`\r`). By default, `.` matches everything except line terminators. Useful for matching multiline blocks.

`/<div>.*?</div>/s` matches a div and its contents even if they span multiple lines

u

**Unicode**

Enables full Unicode matching. Without it, characters outside the Basic Multilingual Plane (emojis, CJK, math symbols) may be treated as two separate code units. Also enables Unicode property escapes like `\p{Letter}` and `\p{Emoji}`.

`/\p{Emoji}/gu` correctly matches emojis like `🔥`, `👋`, `🎉`

### Common Flag Combinations

`gi`

— Find all matches, case-insensitive. The most common combination for text
search.

`gm`

— Find all matches across multiple lines. Useful for log files and config
files.

`gis`

— Global, case-insensitive, dot-all. For matching multiline HTML/XML
blocks.

`gu`

— Global with Unicode. Required when working with internationalized text
or emoji.

`gms`

— Global, multiline, dot-all. Full power for parsing structured multiline
content.

### How Does JavaScript Regex Differ from Other Flavors?

This tool uses JavaScript's native `RegExp` engine, which follows the ECMAScript specification. Some differences to be aware of when porting patterns to other environments:

| Feature | JavaScript | PCRE (grep -P, PHP) | Python re |
| --- | --- | --- | --- |
| Named groups | `(?<name>...)` | `(?P<name>...)` or `(?<name>...)` | `(?P<name>...)` |
| Lookbehind | Variable-length (ES2018+) | Fixed-length only | Fixed-length only |
| Unicode properties | `\p{L}` (with `u` flag) | `\p{L}` (built-in) | Via `regex` module |
| Atomic groups | Not supported | `(?>...)` | Not supported |
| Recursion | Not supported | `(?R)`, `(?1)` | Via `regex` module |
| Possessive quantifiers | Not supported | `a++`, `a*+` | Not supported |
| Backreference in replace | `$1`, `$&` | `\1`, `$1` | `\1`, `\g<1>` |

### How Can I Improve Regex Performance?

- **Avoid catastrophic backtracking** — patterns like `(a+)+b` can cause the engine to hang on long non-matching strings. Use atomic-like constructs or rewrite as `a+b`.
- **Be specific with quantifiers** — prefer `[^"]*` over `.*?` when matching content between delimiters. The negated character class is faster because it does not need backtracking.
- **Anchor when possible** — if you know the match starts at the beginning of a line, use `^` to let the engine skip positions early.
- **Use non-capturing groups** — write `(?:...)` instead of `(...)` when you do not need the captured value. It avoids allocating memory for the group.
- **Monitor execution time** — this tool displays the match time for each test. If a pattern takes more than a few milliseconds, consider simplifying it.

### Privacy

All pattern matching and text processing happens entirely in your browser using JavaScript's built-in `RegExp` engine. No data is transmitted to any server — your patterns and test strings never leave your device.

### Linux Command Reference

Regular expressions are deeply integrated into the Linux command line. Here
are common tools with their regex capabilities.

#### grep — Match Lines with a Pattern

```bash
grep -Pn '\b[A-Z][a-z]+\b' /var/log/nginx/access.log | head -5
```

**Output — Matches (PCRE)**

```text
3:The Quick Brown Fox Jumps Over The Lazy Dog
15:Server nginx/1.25.4...Starting worker process
42:Connection from Remote host established
```

#### grep -oP — Extract Matches Only

```bash
echo '192.168.1.1 and 10.0.0.254' | grep -oP '\b(?:\d{1,3}\.){3}\d{1,3}\b'
```

**Output — Extracted IPs**

```text
192.168.1.1
10.0.0.254
```

#### sed — Find and Replace

```bash
echo 'Date: 2025-06-15' | sed -E 's/([0-9]{4})-([0-9]{2})-([0-9]{2})/\3\/\2\/\1/'
```

**Output — Reformatted Date**

```text
Date: 15/06/2025
```

#### awk — Pattern-Based Processing

```bash
echo -e 'admin@example.com\ndev@test.org\ninvalid' | awk '/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ {print "Valid:", $0}'
```

**Filtered Output**

```text
Valid: admin@example.com
Valid: dev@test.org
```

#### find — Search Files by Regex Name

```bash
find /etc/nginx -regextype posix-extended -regex '.*\.(conf|key|crt)$' -type f | head -5
```

**Output — Matching Files**

```text
/etc/nginx/snippets/disable_assets_log.conf
/etc/nginx/snippets/server_ssl.conf
/etc/nginx/conf.d/default.conf
/etc/nginx/nginx.conf
/etc/nginx/ssl/server.crt
```

### Related

See the regex patterns used in [Implementing Content Security Policy with Nginx](https://jmrp.io/blog/003-implementing-content-security-policy-nginx/) for real-world CSP validation examples, or try the [HTTP Headers Analyzer](https://jmrp.io/tools/http-headers-analyzer/) to inspect regex-validated security headers.

