Code & computing / QUICK REFERENCE
Regular expressions
JavaScript regular expressions with input and match results, character classes, anchors, groups and common string operations.
JavaScript RegExp. Pattern examples show the first match from a fresh regex.exec(input), plus captures where relevant. “No match” means null. Strings use JavaScript escapes, so \n is a newline. The four operation examples describe their own results.
Characters and classes
- Any ordinary character
/./Excludes line terminators unless dotAll is enabled. [2][1][5]
- Input
"a"ResultMatch "a" - Input
"\n"ResultNo match
-
- ASCII digit
/\d/Matches 0 through 9 in JavaScript. [2][1][5]
- Input
"a1"ResultMatch "1" - Input
"٣"ResultNo match
-
- Word character
/\w/Primarily ASCII letters, digits and underscore; not a universal alphabet class. [2][1][5]
- Input
"_"ResultMatch "_" - Input
"é"ResultNo match
-
Repetition and anchors
- Exact count
/\d{4}/Requires four consecutive digits, not necessarily the whole input. [3][1][5]
- Input
"a12345"ResultMatch "1234" - Input
"123"ResultNo match
-
- Bounded count
/\d{2,4}/Matches between two and four digits. [3][1][5]
- Input
"12345"ResultMatch "1234"
-
- Lazy repetition
/a.*?b/Chooses the shortest successful expansion. On "a12bZZb", this matches "a12b"; the greedy /a.*b/ matches "a12bZZb". [3][1][5][8]
- Input
"a12bZZb"ResultMatch "a12b" - Input
"a12c"ResultNo match
-
- Start anchor
/^atlas/Requires the match at input start without the m flag. [3][1][5][6]
- Input
"atlas is first"ResultMatch "atlas" - Input
"my atlas"ResultNo match
-
- End anchor
/atlas$/Without m, the match must end at the end of the input: a trailing newline prevents this match. With m, $ can also match just before a line terminator. [3][1][5][6]
- Input
"my atlas"ResultMatch "atlas" - Input
"atlas\n"ResultNo match
-
Groups and common operations
- Capture a group
/(ab)+/The full match can repeat ab; group 1 holds the last captured iteration. [4][1][5]
- Input
"abab"ResultMatch "abab"; group 1 = "ab"
-
- Group without capturing
/(?:ab)+/Groups repetition without creating a capture slot. [4][1][5]
- Input
"abab"ResultMatch "abab"
-
- Named capture
/(?<year>\d{4})/Reads the capture through groups.year after a successful match. [4][1][5]
- Input
"in 2026"ResultMatch "2026"; groups.year = "2026"
-
- Repeated word
/\b(\w+)\s+\1\b/Backreference repeats the captured characters. [4][1][5]
- Input
"word word"ResultMatch "word word"; group 1 = "word"
-
- Ignore case
/atlas/iCase behavior depends on Unicode and engine rules. [4][1][5]
- Input
"ATLAS"ResultMatch "ATLAS" - Input
"other"ResultNo match
-
Reserved placement, separate from reference controls. No ad network is active.
No matching entry. Try a shorter word or clear the search to see the complete sheet.
Flags and repeated tests
m: line boundaries
The multiline flag lets ^ and $ match line boundaries as well as input boundaries. It does not make a dot match a newline.
/atlas$/.test("atlas\n") // false
/atlas$/m.test("atlas\n") // true
/a.b/m.test("a\nb") // falseInput boundary rules ↓g: keep track of the next match
Repeated calls on the same global regex use lastIndex. A failed search resets it to zero. Sticky y regexes also carry state; use a fresh regex for independent checks.
const re = /\d/g;
re.test("1 2"); // true; lastIndex = 1
re.test("1 2"); // true; lastIndex = 3
re.test("1 2"); // false; lastIndex = 0lastIndex rules ↓Sources
cheatsheetatlas.com/sheets/regex/ · Updated 2026-10-27 · JavaScript RegExp · common modern features