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.