Regex Tester
Test regular expressions with real-time pattern matching, capture groups, and a quick reference guide.
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 backreferenceLookaheads & 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 abcFlags
gGlobal — find all matches, not just the firstiCase-insensitive — A matches amMultiline — ^ and $ match line boundariessDotall — . matches newlines toouUnicode — enables full Unicode matchingySticky — match only at current positionExamples — click to load
/[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}/gi Email addressMatches 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 URLhttps? 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 colourAlternation (|) handles 3-digit, 6-digit and 8-digit (with alpha) hex colours.
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*]).{8,}$/gm Password strengthFour 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 addressEach 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 wordsUses 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 → ISOReorders 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-partRedacts the name before @ while keeping the domain ($1) — handy for sanitising logs.
/(?<user>\w+)@(?<domain>[\w.]+)/g → $<domain>/$<user> Named-group reorderUses named groups $<user> and $<domain> in the replacement instead of numbers.