Basic Patterns
4 snippetsFundamental regex syntax
Literal Match
hello # Matches "hello"Any Character
. # Any single character
h.t # hat, hit, hot, h@tEscape Special
\. # Literal dot
\$ # Literal dollar sign
\(\) # Literal parenthesesAnchors
^start # Start of line
end$ # End of line
^exact$ # Exact match
\bword\b # Word boundaryCharacter Classes
3 snippetsMatch sets of characters
Brackets
[abc] # a, b, or c
[^abc] # NOT a, b, or c
[a-z] # Any lowercase letter
[A-Za-z] # Any letter
[0-9] # Any digitShorthand
\d # Digit [0-9]
\D # Non-digit
\w # Word char [A-Za-z0-9_]
\W # Non-word char
\s # Whitespace
\S # Non-whitespacePOSIX Classes
[:alpha:] # Letters
[:digit:] # Digits
[:alnum:] # Alphanumeric
[:space:] # WhitespaceQuantifiers
3 snippetsSpecify repetition
Basic
a* # 0 or more
a+ # 1 or more
a? # 0 or 1
a{3} # Exactly 3
a{2,4} # 2 to 4
a{2,} # 2 or moreGreedy vs Lazy
.* # Greedy (match most)
.*? # Lazy (match least)
.+? # Lazy 1 or more
.{2,4}? # Lazy rangeExamples
\d+ # One or more digits
\w{3,8} # 3-8 word characters
https? # http or httpsTired of looking up syntax?
DocuWriter.ai generates documentation and explains code using AI.
Groups & Alternation
5 snippetsGroup patterns and alternatives
Capturing Group
(abc) # Capture "abc"
(\d{3})-(\d{4}) # Phone partsNon-capturing
(?:abc) # Group without captureAlternation
cat|dog # cat OR dog
(jpg|png|gif) # Image extensionsBackreference
(\w+) \1 # Repeated word
(['"]).*?\1 # Matching quotesNamed Groups
(?<name>\w+) # Named capture
\k<name> # Named backreferenceLookahead & Lookbehind
4 snippetsAssert without consuming
Positive Lookahead
foo(?=bar) # foo followed by bar
\d+(?=px) # Digits before "px"Negative Lookahead
foo(?!bar) # foo NOT followed by bar
\d+(?!px) # Digits not before "px"Positive Lookbehind
(?<=\$)\d+ # Digits after "$"
(?<=@)\w+ # Word after "@"Negative Lookbehind
(?<!\$)\d+ # Digits not after "$"Common Patterns
7 snippetsFrequently used expressions
[\w.-]+@[\w.-]+\.\w+URL
https?://[\w.-]+(/[\w./-]*)?Phone (US)
\(?\d{3}\)?[-. ]?\d{3}[-. ]?\d{4}Date (YYYY-MM-DD)
\d{4}-\d{2}-\d{2}IPv4 Address
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}Hex Color
#[0-9A-Fa-f]{6}\bUsername
^[a-zA-Z][a-zA-Z0-9_]{2,15}$Flags & Modifiers
5 snippetsChange regex behavior
Case Insensitive
/pattern/i # JavaScript
(?i)pattern # Inline flagGlobal
/pattern/g # Match allMultiline
/pattern/m # ^ and $ match line breaksDotall
/pattern/s # . matches newlinesCombined
/pattern/gim # Multiple flags