Quick reference for all regex syntax. Click any entry to open it in the interactive tester.
^
Start of string (or line in multiline mode)
^hello→"hello world" — matches at the start
^hello
$
End of string (or line in multiline mode)
world$→"hello world" — matches at the end
world$
\b
Word boundary — position between a word and non-word character
\bcat\b→"the cat sat" — matches "cat" but not "catch"
\bcat\b
\B
Non-word boundary — position not between word and non-word
\Bcat\B→"concatenate" — matches inside a word
\Bcat\B
.
Any character except newline (with s flag, matches newline too)
a.c→"abc", "aXc", "a1c"
a.c
\d
Digit — equivalent to [0-9]
\d+→"123", "42", "0"
\d+
\D
Non-digit — equivalent to [^0-9]
\D+→"abc", "hello", "!@#"
\D+
\w
Word character — equivalent to [a-zA-Z0-9_]
\w+→"hello", "world_123"
\w+
\W
Non-word character — equivalent to [^a-zA-Z0-9_]
\W+→" ", "!@#", "-"
\W+
\s
Whitespace character — space, tab, newline, etc.
\s+→" ", "\t", "\n"
\s+
\S
Non-whitespace character
\S+→"hello", "123"
\S+
[abc]
Character class — matches any one of a, b, or c
[aeiou]→"a", "e", "i", "o", "u"
[aeiou]
[^abc]
Negated class — matches any character except a, b, or c
[^aeiou]→"b", "c", "1", " "
[^aeiou]
[a-z]
Range — matches any character from a to z
[a-zA-Z]→"a", "Z", "m"
[a-zA-Z]
*
0 or more — greedy (matches as much as possible)
ab*→"a", "ab", "abbb"
ab*
+
1 or more — greedy
ab+→"ab", "abbb" (not "a")
ab+
?
0 or 1 — makes the preceding token optional
colou?r→"color", "colour"
colou?r
{n}
Exactly n repetitions
\d{4}→"2024", "1234"
\d{4}
{n,}
n or more repetitions
\d{2,}→"12", "123", "1234"
\d{2,}
{n,m}
Between n and m repetitions (inclusive)
\d{2,4}→"12", "123", "1234"
\d{2,4}
*?
0 or more — lazy (matches as little as possible)
<.*?>→"<b>" in "<b>bold</b>"
<.*?>
+?
1 or more — lazy
.+?(?=,)→"a" in "a,b,c"
.+?(?=,)
??
0 or 1 — lazy (prefers 0)
ab??→"a" (prefers no b)
ab??
(abc)
Capturing group — captures the matched text for backreferences
(\w+)\s\1→"hello hello" — repeated word
(\w+)\s\1
(?:abc)
Non-capturing group — groups without capturing
(?:ab)+→"ab", "abab", "ababab"
(?:ab)+
(?<name>abc)
Named capturing group — captures with a name for reference
(?<year>\d{4})-(?<month>\d{2})→"2024-03" with groups year=2024, month=03
(?<year>\d{4})-(?<month>\d{2})
\1
Backreference — matches the same text as group 1 captured
(\w)\1→"aa", "bb", "zz" — repeated characters
(\w)\1
\k<name>
Named backreference — matches the same text as a named group
(?<word>\w+)\s\k<word>→"hello hello" — repeated word
(?<word>\w+)\s\k<word>
(?=abc)
Positive lookahead — matches if followed by abc
\d+(?= dollars)→"100" in "100 dollars"
\d+(?= dollars)
(?!abc)
Negative lookahead — matches if NOT followed by abc
\d+(?! dollars)→"100" in "100 euros" (not in "100 dollars")
\d+(?! dollars)
(?<=abc)
Positive lookbehind — matches if preceded by abc
(?<=\$)\d+→"100" in "$100"
(?<=\$)\d+
(?<!abc)
Negative lookbehind — matches if NOT preceded by abc
(?<!\$)\d+→"100" in "€100" (not in "$100")
(?<!\$)\d+
\n
Newline character (line feed, LF)
line1\nline2→"line1\nline2" — multiline text
line1\nline2
\t
Tab character
name\tvalue→"name\tvalue" — tab-separated
name\tvalue
\r
Carriage return character (CR)
\r\n→Windows line endings (CRLF)
\r\n
\0
Null character (NUL, Unicode U+0000)
\0→Null byte in binary data
\uXXXX
Unicode character by code point (4 hex digits)
\u00E9→"é" — Unicode letter
\u00E9
\\
Literal backslash character
C:\\Users→"C:\Users" — Windows path
C:\\Users
g
Global — find all matches, not just the first
/\d+/g→All numbers in "a1 b2 c3"
/\d+/g
i
Case-insensitive — match regardless of letter case
/hello/i→"hello", "Hello", "HELLO"
/hello/i
m
Multiline — ^ and $ match start/end of each line
/^\d+/m→Numbers at the start of any line
/^\d+/m
s
Dotall — makes . match newline characters too
/a.b/s→"a\nb" — dot matches newline
/a.b/s
u
Unicode — enables full Unicode matching and \p{} classes
/\p{L}+/u→Unicode letters in any language
/\p{L}+/u
y
Sticky — matches only from lastIndex position
/\d+/y→Anchored match at lastIndex
/\d+/y