/ /
Replace Mode
Matches 0
Match Details
Quick Reference
Characters
. 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
Anchors
^ Start of string/line
$ End of string/line
\b Word boundary
\B Non-word boundary
Quantifiers
* 0 or more
+ 1 or more
? 0 or 1 (optional)
{n} Exactly n
{n,m} Between n and m
*? Lazy (non-greedy)
Groups
(...) Capture group
(?:...) Non-capturing group
(?<name>...) Named capture group
\1 Backreference to group 1
a|b Alternation (a or b)
Lookaround
(?=...) Positive lookahead
(?!...) Negative lookahead
(?<=...) Positive lookbehind
(?<!...) Negative lookbehind

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 to Use

  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

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.

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.

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:

FeatureJavaScriptPCRE (grep -P, PHP)Python re
Named groups(?<name>...)(?P<name>...) or (?<name>...)(?P<name>...)
LookbehindVariable-length (ES2018+)Fixed-length onlyFixed-length only
Unicode properties\p{L} (with u flag)\p{L} (built-in)Via regex module
Atomic groupsNot supported(?>...)Not supported
RecursionNot supported(?R), (?1)Via regex module
Possessive quantifiersNot supporteda++, a*+Not supported
Backreference in replace$1, $&\1, $1\1, \g<1>

Regex Performance Tips

  • 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

grep -Pn ‘\b[A-Z][a-z]+\b’ /var/log/nginx/access.log | head -5
3:The Quick Brown Fox Jumps Over The Lazy Dog15:Server nginx/1.25.4...Starting worker process42:Connection from Remote host established

grep -oP — Extract Matches Only

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

sed — Find and Replace

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

awk — Pattern-Based Processing

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}'
Valid: admin@example.comValid: dev@test.org

find — Search Files by Regex Name

find /etc/nginx -regextype posix-extended -regex '.*\.(conf|key|crt)$' -type f | head -5
/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 for real-world CSP validation examples, or try the HTTP Headers Analyzer to inspect regex-validated security headers.