A compact JavaScript-oriented regex reference for common tokens, anchors, groups and quantifiers.
Common regex tokens
| Pattern | Meaning |
|---|---|
. | Any character except line terminators unless dotAll is enabled |
\d | ASCII digit, equivalent to [0-9] |
\w | ASCII letters, digits and underscore; not a general Unicode word matcher |
\s | Whitespace |
^ / $ | Start / end of input; with m, start / end of a line |
[abc] | One character from a set |
[^abc] | One character not in a set |
* / + / ? | 0+ / 1+ / optional repetitions |
{n,m} | Repeat from n to m times |
(...) | Capturing group |
(?:...) | Non-capturing group |
a|b | Alternation |
\b | Word boundary assertion; inside a character class, this escape means backspace |
Useful JavaScript flags
g global, i case-insensitive, m multiline, s dotAll, u Unicode mode and y sticky matching.
Regex syntax differs across JavaScript, PCRE, Python, .NET and other engines. Test patterns in the engine where they will actually run.
Patterns to try
Enter these patterns without surrounding slashes in the Regex Tester. Use the listed flags.
| Task | Pattern | Flags | Example |
|---|---|---|---|
| Find digit runs | \d+ | g | In “A12 B345”, matches 12 and 345. |
| Find a whole word | \bcat\b | g | In “cat scatter”, matches cat only. |
| Match a literal period | \. | g | In “a.b”, matches the period. |
| Capture two fields | ([A-Z]+)-(\d+) | g | In “AB-42”, captures AB and 42. |
Backslashes in JavaScript strings
A regex literal such as /\d+/g uses one backslash. In a JavaScript string passed to the constructor, escape it again: new RegExp("\\d+", "g"). In this site’s tester, enter \d+ directly. Typing just d+ matches the letter d instead of digits.
Common mistakes
Use \. for a literal period; an unescaped dot is a wildcard. Quantifiers are greedy by default; adding ?, as in .*?, makes them lazy. Group alternatives when applying anchors: ^(cat|dog)$ applies both anchors to either choice.
Word boundaries follow JavaScript’s word-character rules and may not split words as expected in multilingual text. A pattern working on a short example can also be slow on long input; test realistic non-matching cases. For detailed syntax, consult MDN’s regular expression cheat sheet.