Skip to main content

HelpyTools
Convert Inspect & Validate Generate Text & Docs Design & Code
  • Cron Expression
  • Diff
  • HTTP
  • JSON
  • JSON Schema
  • JWT
  • package.json
  • Regex

© 2026 HelpyTools

Regex Tester

Test regular expressions with real-time pattern matching, capture groups, and a quick reference guide.

Pattern
/ /
⮕
Test string
Matches

Enter a pattern and test string to see matches.

Character classes

.Any character except newline
\wWord character [a-zA-Z0-9_]
\WNon-word character
\dDigit [0-9]
\DNon-digit
\sWhitespace (space, tab, newline…)
\SNon-whitespace
\tTab
\nNewline
\rCarriage return
[abc]Character class — any of a, b or c
[^abc]Negated class — anything except a, b, c
[a-z]Range — any lowercase letter
[a-zA-Z]Range — any letter (case-insensitive)

Anchors & boundaries

^Start of string (or line with m flag)
$End of string (or line with m flag)
\bWord boundary
\BNon-word boundary
\AStart of string (no multiline)
\ZEnd of string (no multiline)

Quantifiers

*0 or more (greedy)
+1 or more (greedy)
?0 or 1 — makes preceding token optional
{n}Exactly n times
{n,}At least n times
{n,m}Between n and m times
*?0 or more (lazy — as few as possible)
+?1 or more (lazy)
??0 or 1 (lazy)

Groups & alternation

(abc)Capturing group — stores match in $1, $2…
(?:abc)Non-capturing group — groups without storing
(?<name>abc)Named capturing group — accessible as $<name>
a|bAlternation — matches a or b
\1Backreference — refers to group 1's match
\k<name>Named backreference

Lookaheads & lookbehinds

(?=abc)Positive lookahead — followed by abc
(?!abc)Negative lookahead — not followed by abc
(?<=abc)Positive lookbehind — preceded by abc
(?<!abc)Negative lookbehind — not preceded by abc

Flags

gGlobal — find all matches, not just the first
iCase-insensitive — A matches a
mMultiline — ^ and $ match line boundaries
sDotall — . matches newlines too
uUnicode — enables full Unicode matching
ySticky — match only at current position

Examples — click to load

/[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}/gi Email address

Matches standard email addresses. The first part allows word chars, dots, + and -. After @, matches a domain and a 2+ char TLD.

/https?:\/\/(?:www\.)?[-\w]+(?:\.\w+)+(?:\/[-\w%@+.~#?&/=]*)? /gi URL

https? makes the s optional. (?:www\.)? is a non-capturing optional group. The path segment uses [-\w%@+.~#?&/=]* to cover query strings.

/^(?:\+?(\d{1,3})[-.\s]?)?…/gm Phone number (international)

Uses ^/$ anchors with the m flag to match one per line. \+? makes the country code prefix optional.

/^#(?:[0-9a-fA-F]{3}){1,2}$|^#[0-9a-fA-F]{8}$/gm Hex colour

Alternation (|) handles 3-digit, 6-digit and 8-digit (with alpha) hex colours.

/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*]).{8,}$/gm Password strength

Four lookaheads enforce rules independently: lowercase, uppercase, digit, special char. .{8,} enforces minimum 8 characters.

/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}…/gm IPv4 address

Each octet matches: 25[0-5] (250–255), 2[0-4]\d (200–249), or [01]?\d\d? (0–199). Repeats {3} times for first three octets.

/(\b\w+\b)(?:\s+\1\b)+/gi Duplicate words

Uses a backreference \1 to detect the same word repeated. The i flag ignores case.

/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/gm ISO date (YYYY-MM-DD)

Months reject 00 and 13+. Days handle 01–09, 10–29, 30–31. Can't validate Feb 30th — that needs code.

Replace examples — click to load

/(\d{2})\/(\d{2})\/(\d{4})/g  →  $3-$1-$2 Reformat date → ISO

Reorders US MM/DD/YYYY dates to ISO YYYY-MM-DD using capture-group backreferences $1–$3.

/(\w+),\s*(\w+)/g  →  $2 $1 Swap “Last, First”

Turns Last, First into First Last by swapping the two capture groups.

/[\w.+-]+@([\w-]+\.[a-zA-Z]{2,})/gi  →  ***@$1 Mask email local-part

Redacts the name before @ while keeping the domain ($1) — handy for sanitising logs.

/(?<user>\w+)@(?<domain>[\w.]+)/g  →  $<domain>/$<user> Named-group reorder

Uses named groups $<user> and $<domain> in the replacement instead of numbers.

Testing and debugging JavaScript regular expressions

Write a pattern, toggle flags (g, i, m, s, u), and inspect live highlighted matches, numbered and named capture groups, and replacement previews against your sample text. Patterns execute inside a Web Worker so a runaway catastrophic backtracking expression never freezes your browser tab.

  • Flags at a glance: Use g to find all matches, i for case-insensitive matching, m so ^ and $ match every line, and s so . matches newlines.
  • Inspect capture groups: Wrap sub-patterns in (…) or (?<name>…) to verify extracted fields before pasting the regex into application code.
  • Built-in reference & examples: Expand the Quick Reference above for token syntax and clickable starter patterns for emails, URLs, ISO dates, and log parsing.

Which regex engine does this tester use?

It uses your browser's native ECMAScript (JavaScript) RegExp engine, including named capture groups, lookbehind assertions, and Unicode property escapes (\p{…} with the u flag).

Why did my regex stop with a timeout?

Nested quantifiers such as (a+)+$ can cause exponential backtracking on non-matching input. Running matches in a worker with a time limit catches unsafe patterns before they reach production.

Can I share a pattern and test input with a teammate?

Yes. Click Share to encode the pattern, flags, and sample text into the URL fragment — nothing is stored on a server.

Works well with Diff Checker Sort Lines Case Converter Text Stats Code Runner