0% found this document useful (0 votes)
5 views4 pages

Regex Reference

This document serves as a reference guide for regular expressions, detailing various symbols and their functions. It includes explanations and examples for characters such as the dot (.), caret (^), dollar sign ($), and more. Additionally, it covers advanced concepts like lookaheads, lookbehinds, and flags/modifiers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Regex Reference

This document serves as a reference guide for regular expressions, detailing various symbols and their functions. It includes explanations and examples for characters such as the dot (.), caret (^), dollar sign ($), and more. Additionally, it covers advanced concepts like lookaheads, lookbehinds, and flags/modifiers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Regular Expressions Reference Guide

Dot (.)
Symbol: .
Description: Matches any single character except newline
Example: a.c matches "abc", "axc", "a!c"

Caret (^)
Symbol: ^
Description: Matches the beginning of a line or string
Example: ^hello matches "hello" at start

Dollar Sign ($)


Symbol: $
Description: Matches the end of a line or string
Example: world$ matches "world" at end

Backslash (\)
Symbol: \
Description: Escape character for special chars
Example: \. matches ".", \d matches digits

Character Class []
Symbol: [ ]
Description: Matches any single character inside brackets
Example: [abc] or [a-z]

Negated Class [^...]


Symbol: [^...]
Description: Matches any character NOT in set
Example: [^0-9] matches non-digit

Asterisk (*)
Symbol: *
Description: Matches zero or more of preceding element
Example: a* matches "", "a", "aa"

Plus (+)
Symbol: +
Description: Matches one or more of preceding element
Example: a+ matches "a", "aa"

Question Mark (?)


Symbol: ?
Description: Matches zero or one occurrence
Example: colou?r matches "color" or "colour"

Curly Braces ({})


Symbol: {n},{n,},{n,m}
Description: Specifies exact number of occurrences
Example: a{2,4}

Grouping ( )
Symbol: ( )
Description: Groups expressions and captures
Example: (abc)+ matches "abcabc"

Alternation |
Symbol: |
Description: Matches either/or expression
Example: cat|dog matches 'cat' or 'dog'

Word Characters
Symbol: \w
Description: Matches letters, digits, underscore
Example: [a-zA-Z0-9_]

Non-Word Characters
Symbol: \W
Description: Matches non-word characters
Example: [^a-zA-Z0-9_]

Digits
Symbol: \d
Description: Matches digits
Example: [0-9]

Non-Digits
Symbol: \D
Description: Matches non-digits
Example: [^0-9]

Whitespace
Symbol: \s
Description: Matches spaces, tabs, newlines
Example: [ \t\n\r\f]

Non-Whitespace
Symbol: \S
Description: Matches any non-whitespace
Example: [^ \t\n\r\f]

Word Boundary
Symbol: \b
Description: Matches word boundary position
Example: \bword\b matches 'word'

Non-Word Boundary
Symbol: \B
Description: Matches non-boundary positions
Example: \Bion\B matches 'ion' in 'opinion'

Positive Lookahead
Symbol: (?=...)
Description: Matches if followed by pattern
Example: \d+(?=€)

Negative Lookahead
Symbol: (?!...)
Description: Matches if NOT followed
Example: \d+(?!€)

Positive Lookbehind
Symbol: (?<=...)
Description: Matches if preceded by pattern
Example: (?<=\$)\d+

Negative Lookbehind
Symbol: (?<!...)
Description: Matches if NOT preceded
Example: (?<!\$)\d+

Escape Sequences
Symbol Description
\n Newline
\t Tab
\r Carriage Return
\f Form Feed
\v Vertical Tab
\0 Null
\xHH Hexadecimal char
\uHHHH Unicode char

Flags and Modifiers


Flag Description
g Global - find all matches
i Case-insensitive
m Multiline (^ and $ match lines)
s Dot matches newlines
u Unicode support
x Extended syntax (ignore whitespace)

You might also like