Back to Learn
Published: June 2026By Web Util Slyce Team

Regex Guide & Patterns

A comprehensive regular expression reference. Test any pattern interactively with our Regex Tester.

Anchors

PatternDescription
^Start of string (or line in multiline mode)
$End of string (or line in multiline mode)
\bWord boundary
\BNot a word boundary

Character Classes

PatternDescription
.Any single character (except newline with /m)
\dDigit [0-9]
\DNon-digit [^0-9]
\wWord character [a-zA-Z0-9_]
\WNon-word character
\sWhitespace (space, tab, newline)
\SNon-whitespace
[abc]Any character in the set
[^abc]Any character NOT in the set
[a-z]Range of characters

Quantifiers

PatternDescription
*Zero or more (greedy)
+One or more (greedy)
?Zero or one (optional)
{n}Exactly n times
{n,}n or more times
{n,m}Between n and m times
*?Zero or more (lazy/non-greedy)
+?One or more (lazy/non-greedy)

Groups & Alternation

PatternDescription
(...)Capturing group (creates a backreference)
(?:...)Non-capturing group
(?=...)Positive lookahead
(?!...)Negative lookahead
(?<=...)Positive lookbehind
(?<!...)Negative lookbehind
|Alternation (OR)
\1Backreference to group 1

Escape Sequences

PatternDescription
\Escape special character
\tTab
\nNewline (line feed)
\rCarriage return
\0Null character
\xhhCharacter by hex code (e.g., \x20 for space)

Flags Reference

/g

Global: Find all matches, not just the first

/i

Case-Insensitive: Ignore case when matching

/m

Multiline: ^ and $ match line start/end

/s

Dotall: '.' matches newlines

/u

Unicode: Unicode-aware matching

/y

Sticky: Match from lastIndex position