Regex Tester
Test regular expressions with real-time highlighting, capture groups, replace mode, and common pattern presets.
Quick Reference
. Any character (except newline)\d Digit [0-9]\D Non-digit\w Word char [A-Za-z0-9_]\W Non-word char\s Whitespace\S Non-whitespace^ Start of string/line$ End of string/line\b Word boundary\B Non-word boundary* 0 or more+ 1 or more? 0 or 1 (optional){n} Exactly n{n,m} Between n and m*? Lazy (non-greedy)(...) Capture group(?:...) Non-capturing group(?<name>...) Named capture group\1 Backreference to group 1a|b Alternation (a or b)(?=...) Positive lookahead(?!...) Negative lookahead(?<=...) Positive lookbehind(?<!...) Negative lookbehindAbout 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 labelsReplace 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 to Use
- Enter your regex pattern in the pattern field
- Set the desired flags (g, i, m, s, u) using the checkboxes
- Type or paste your test string in the textarea
- Matches are highlighted in real time with detailed info below
Toggle Replace Mode to test substitutions — enter a replacement string with
$1,$&, or$<name>backreferencesClick any preset to load a common pattern with matching sample text
Expand Quick Reference at the bottom for a compact regex syntax cheat sheet
Regex Flags Explained
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.
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)
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”
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
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
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.JavaScript vs Other Regex 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> |
Regex Performance Tips
Avoid catastrophic backtracking — patterns like
(a+)+bcan cause the engine to hang on long non-matching strings. Use atomic-like constructs or rewrite asa+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
grep -oP — Extract Matches Only
sed — Find and Replace
awk — Pattern-Based Processing
find — Search Files by Regex Name
Related
See the regex patterns used in Implementing Content Security Policy with Nginx for real-world CSP validation examples, or try the HTTP Headers Analyzer to inspect regex-validated security headers.