Tokens, groups, lookarounds and flags for writing and reading regular expressions in JavaScript and beyond. All rows are plain text - search to filter, click Copy to grab the pattern.
Reference rack
STATUSREADY
ROWS46
NETWORKLOCAL
MODEREFERENCE
| Item / pattern | What it means / how to use it | |
|---|---|---|
| . | Any character except a line terminator (with the /s flag, includes newlines). | |
| \d / \D | Any digit / any non-digit. | |
| \w / \W | Word character [A-Za-z0-9_] / any non-word character. | |
| \s / \S | Whitespace (space, tab, newline) / any non-whitespace. | |
| [abc] | Character set - matches one of a, b, or c. | |
| [a-z] / [^a-z] | Range match / negated set (anything not a to z). | |
| \t / \n / \r | Tab, newline, carriage return escapes. | |
| \x41 / \u00A0 | Hex escape / Unicode escape (for example U+00A0 no-break space). | |
| ^ | Start of the string (or start of a line with the /m flag). | |
| $ | End of the string (or end of a line with /m). | |
| \b / \B | Word boundary / not a word boundary. | |
| (abc) | Capturing group (numbered $1, $2...). | |
| (?:abc) | Non-capturing group - groups without storing the match. | |
| (?<name>abc) | Named group; readable as match.groups.name in JS. | |
| abc|def | Alternation - match abc or def. | |
| a{2} / a{2,4} / a{2,} | Exact, range, and open-ended quantifiers. | |
| * / + / ? | 0-or-more / 1-or-more / 0-or-1; make lazy with *? +? ??. | |
| (?>abc) | Atomic group - no backtracking back into it. | |
| (?=text) | Positive lookahead - the following text must match. | |
| (?!text) | Negative lookahead - the following text must NOT match. | |
| (?<=text) | Positive lookbehind; JS supports fixed-width lookbehind. | |
| (?<!text) | Negative lookbehind. | |
| /g | Global flag - find all matches instead of stopping at the first. | |
| /i | Case-insensitive matching. | |
| /m | Multiline - ^ and $ now match at each line boundary. | |
| /s | DotAll - the dot matches newlines too. | |
| /u | Unicode mode - proper codepoint handling and \p{} support. | |
| /y | Sticky - matches only at exactly lastIndex. | |
| Email, simple | [^\s@]+@[^\s@]+\.[^\s@]+ - a solid filter, not an RFC-compliant validator. | |
| URL (http/https) | https?://[\w-]+(\.[\w-]+)+\S* - quick link detection. | |
| IPv4 | (\d{1,3}\.){3}\d{1,3} - match, then validate each octet as 0-255. | |
| UUID | [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} - add /i for upper case. | |
| Hex color | #([0-9a-f]{3}|[0-9a-f]{6})\b - with /i for uppercase letters. | |
| US phone, loose | \+?1?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4} - lenient by design. | |
| ISO 8601 date | \d{4}-\d{2}-\d{2} - matches YYYY-MM-DD. | |
| URL slug | ^[a-z0-9]+(?:-[a-z0-9]+)*$ - lowercase words joined by single hyphens. | |
| Blank lines | ^\s*$ - with the /m flag to find every one. | |
| regex.test(str) | Boolean - does a match exist? | |
| str.match(pattern) | All matches with /g; otherwise first match plus groups. | |
| str.matchAll(pattern) | Iterator over every match including groups; requires the /g flag. | |
| str.replace(pattern, repl) | "$1" and named groups work inside the replacement; /g replaces all. | |
| str.search(pattern) | Index of the first match or -1. | |
| str.split(pattern) | Split the string at every regex boundary. | |
| Escape metacharacters | \. \* \+ \? \( \) \[ \] \{ \} \| \^ \$ \\ - backslash-escape any of them when matching literally. | |
| Backreference | "\1" or $1 reuse what the first capturing group matched. | |
| Catastrophic backtracking | (a+)+ and similar stacked quantifiers can freeze the engine on long inputs - avoid nested quantifiers. |