A quick reference for pattern matching — Python · JavaScript · Go · PHP · Java · Ruby
| ^ | Start of string / line | |
| $ | End of string / line | |
| \b | Word boundary | |
| \B | Not a word boundary | |
| \A | Start of string (no multiline) | |
| \Z | End of string (no multiline) | |
| \z | Absolute end of string | |
| \G | Start of current search (pos) | |
| \K | Reset match start (keep left) | |
| (?m)^ | Start of each line (multiline) | |
| (?m)$ | End of each line (multiline) |
| . | Any char except newline | |
| \w | Word char [a-zA-Z0-9_] | |
| \W | Non-word character | |
| \d | Digit [0-9] | |
| \D | Non-digit | |
| \s | Whitespace [ \t\n\r\f] | |
| \S | Non-whitespace | |
| [abc] | Any of a, b, or c | |
| [^abc] | Not a, b, or c | |
| [a-z] | Range a to z | |
| [a-zA-Z0-9] | Alphanumeric | |
| \p{L} | Unicode letter (PCRE/Java) | |
| \p{N} | Unicode number |
| * | 0 or more (greedy) | |
| + | 1 or more (greedy) | |
| ? | 0 or 1 (greedy) | |
| {n} | Exactly n times | |
| {n,} | n or more times | |
| {n,m} | Between n and m times | |
| *? | 0 or more (lazy) | |
| +? | 1 or more (lazy) | |
| ?? | 0 or 1 (lazy) | |
| *+ | 0 or more (possessive) | |
| ++ | 1 or more (possessive) |
| (abc) | Capture group | |
| (?:abc) | Non-capturing group | |
| (?<name>abc) | Named capture group | |
| (?P<name>abc) | Named group (Python) | |
| \1 | Backreference to group 1 | |
| (?P=name) | Named backreference (Python) | |
| (?>abc) | Atomic group (no backtrack) | |
| a|b | Alternation: a or b |
| (?=abc) | Positive lookahead | |
| (?!abc) | Negative lookahead | |
| (?<=abc) | Positive lookbehind | |
| (?<!abc) | Negative lookbehind |
| i | Case insensitive | |
| g | Global — find all matches | |
| m | Multiline — ^ and $ per line | |
| s | Dotall — . matches \n too | |
| x | Verbose — ignore whitespace | |
| u | Unicode mode | |
| (?ims) | Multiple inline flags | |
| (?-i) | Turn off flag inline |
| \n | Newline (LF, U+000A) | |
| \r | Carriage return (CR, U+000D) | |
| \t | Horizontal tab (U+0009) | |
| \v | Vertical tab (U+000B) | |
| \f | Form feed (U+000C) | |
| \a | Bell (U+0007) | |
| \e | Escape (U+001B) | |
| \0 | Null character (U+0000) | |
| \xFF | Hex byte (e.g. \x41 = A) | |
| \uFFFF | Unicode code point (4 hex) | |
| \u{1F600} | Unicode (JS with /u flag) | |
| \cX | Control char (e.g. \cM = CR) | |
| \\ | Literal backslash | |
| \. \* \+ \? \^ \$ | Literal meta characters | |
| \( \) \[ \] \{ \} | Literal brackets | |
| \| \/ | Literal pipe / slash |
| $1 or \1 | Insert capture group 1 | |
| ${1} | Group 1 (unambiguous) | |
| $& | Entire match | |
| $` | String before match | |
| $' | String after match | |
| $$ | Literal $ in replacement | |
| $<name> | Named group (JS) | |
| \g<name> | Named group (Python) | |
| \g<1> | Group by number (Python) | |
| ${name} | Named group (.NET / JS) | |
| \U\1 | Uppercase group (Perl/PCRE) | |
| \L\1 | Lowercase group (Perl/PCRE) | |
| \E | End \U or \L |
| regex101.com | Online tester with explanation (PCRE, JS, Python, Go) |
| regexr.com | Visual regex tester with community patterns |
| regexcrossword.com | Learn regex by solving crossword puzzles |
| regular-expressions.info | Deep dive reference for all flavors |
| MDN Regex Guide | JavaScript regex documentation |
| Python re docs | Official Python regex module reference |
| Go regexp syntax | Go RE2 syntax reference |
| PCRE2 syntax | Full PCRE2 pattern syntax |
| [\w.+-]+@[\w-]+\.[a-z]{2,} | ||
| https?://[\w./%-]+(\?[\w=&%-]+)? | URL | |
| \d{1,3}(\.\d{1,3}){3} | IPv4 address | |
| ([0-9a-f]{2}:){5}[0-9a-f]{2} | MAC address | |
| ^\+?[\d\s()\-]{7,15}$ | Phone number | |
| ^#?[0-9a-fA-F]{6}$ | Hex color (#RRGGBB) | |
| ^#?([0-9a-fA-F]{3}){1,2}$ | Hex color (3 or 6 digits) | |
| \d{4}-\d{2}-\d{2} | Date YYYY-MM-DD | |
| \d{2}[\/.-]\d{2}[\/.-]\d{4} | Date DD/MM/YYYY | |
| \d{2}:\d{2}(:\d{2})? | Time HH:MM[:SS] |
| ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$ | Strong password | |
| ^[a-zA-Z0-9_]{3,20}$ | Username | |
| ^\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}$ | Credit card number | |
| ^[a-z][a-z0-9\-]{1,61}[a-z0-9]$ | Domain name | |
| [a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12} | UUID / GUID | |
| <[^>]+> | HTML tag (basic) | |
| \/\*[\s\S]*?\*\/ | /* Block comment */ | |
| ^\s+|\s+$ | Leading/trailing whitespace | |
| \b\d+(\.\d+)?\b | Integer or float | |
| ^[01]?\d|2[0-3]):[0-5]\d$ | 24-hour time HH:MM |
| /pattern/flags | Regex literal | |
| new RegExp(str, flags) | Dynamic regex | |
| re.test(str) | Returns true/false | |
| str.match(re) | Array of matches or null | |
| str.matchAll(re) | Iterator of all matches | |
| str.search(re) | Index of first match or -1 | |
| str.replace(re, '$1') | Replace with string or fn | |
| str.replaceAll(re, s) | Replace all (needs g flag) | |
| str.split(re) | Split by pattern |
| re.match(p, s) | Match at start of string | |
| re.search(p, s) | Search anywhere in string | |
| re.findall(p, s) | List of all matches | |
| re.finditer(p, s) | Iterator of match objects | |
| re.sub(p, repl, s) | Replace matches | |
| re.subn(p, repl, s) | Replace + count | |
| re.split(p, s) | Split by pattern | |
| re.compile(p, re.I) | Compile with flags | |
| m.group(1) | Get capture group value | |
| m.groupdict() | Named groups as dict | |
| m.span() | Start and end positions |
| [:alpha:] | Letters [a-zA-Z] | |
| [:digit:] | Digits [0-9] | |
| [:alnum:] | Letters and digits | |
| [:space:] | Whitespace | |
| [:upper:] | Uppercase letters | |
| [:lower:] | Lowercase letters | |
| [:punct:] | Punctuation | |
| [:print:] | Printable characters | |
| [:xdigit:] | Hex digits [0-9a-fA-F] |