Skip to main content
CodeLint.Dev Dev Tools

Anchors

^ Start of string (or line with multiline flag)
$ End of string (or line with multiline flag)
\b Word boundary — between \w and \W
\B Not a word boundary
\A Start of string (no multiline, most engines)
\Z End of string (no multiline, most engines)
(?=...) Positive lookahead — followed by pattern
(?!...) Negative lookahead — NOT followed by pattern
(?<=...) Positive lookbehind — preceded by pattern
(?<!...) Negative lookbehind — NOT preceded by pattern

Character Classes

. Any character except newline (with /s also newline)
\d Digit — [0-9]
\D Not a digit — [^0-9]
\w Word character — [a-zA-Z0-9_]
\W Not a word character — [^a-zA-Z0-9_]
\s Whitespace — space, tab, newline, etc.
\S Not whitespace
[abc] Character set — matches a, b, or c
[^abc] Negated set — anything except a, b, or c
[a-z] Range — any lowercase letter
[a-zA-Z] Range — any letter (upper or lower)
\p{L} Unicode letter (requires /u flag in JS)
\p{N} Unicode number (requires /u flag in JS)

Quantifiers

* 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 / non-greedy)
+? 1 or more (lazy)
?? 0 or 1 (lazy)
{n,m}? Between n and m (lazy)
*+ 0 or more (possessive, no backtrack)
++ 1 or more (possessive)

Groups & Alternation

(abc) Capturing group — captures abc
(?:abc) Non-capturing group — groups but does not capture
(?<name>abc) Named capturing group
\1 Backreference to group 1
\k<name> Named backreference
a|b Alternation — matches a or b
(?(1)yes|no) Conditional — if group 1 matched, use "yes" else "no"
(?|a(b)|(c)d) Branch reset group (PCRE)

Escape Sequences

\n Newline (LF)
\r Carriage return (CR)
\t Tab
\v Vertical tab
\f Form feed
\0 Null byte
\xhh Hex character (e.g. \x41 = A)
\uhhhh Unicode character (e.g. \u0041 = A)
\\ Literal backslash
\. Literal dot (escape special chars)

Flags / Modifiers

g Global — find all matches, not just the first
i Case-insensitive matching
m Multiline — ^ and $ match start/end of each line
s Dotall — dot matches newline characters too
u Unicode — enables full Unicode matching (\p{...})
y Sticky — match only at lastIndex position (JS)
d Indices — populate match.indices (JS ES2022)
x Extended — allow whitespace and comments (PCRE)

Substitution (Replace)

$0 / $& Whole match
$1, $2… Captured group 1, 2, etc.
$<name> Named capture group in replacement
$' String after the match
$` String before the match
$$ Literal dollar sign in replacement

POSIX Classes (in [...])

[:alpha:] Letters — [a-zA-Z]
[:digit:] Digits — [0-9]
[:alnum:] Letters and digits
[:space:] Whitespace characters
[:upper:] Uppercase letters
[:lower:] Lowercase letters
[:punct:] Punctuation characters
[:xdigit:] Hexadecimal digits [0-9a-fA-F]