Regular expression reference

Regular expression reference table list

Regular ExpressionExplanation
a-zmatches small letters starting from 'a' - 'z'
A-Zmatches capital letters starting from 'A' - 'Z'
.dot(.) represents single wildcard character (joker in a card game)
\escape character. To escape the actual representation and represent actual character
^is used to negate a batch of character like [^a-z] -- matches the characters other than 'a' - 'z'
{m, n}m, n are integers here. represents any preceding character appears atleast 'm' times and atmost 'n' times. ex: a[1, 3] 'a' can appear 1-3 times
*represents the preceding expression can occur from 0 to any number of times. ex: \d* any digit can appear from 0 to any number of times
+represents the preceding expression will occur atleast once. ex: \d+ - digit will appear atleast once.
?represents the preceding character is optional(it may occur). ex: a? -- the match may have 'a' & ab?c -- 'b' is optional.
\wrepresents alphanumeric [a-zA-Z0-9_]
\rcarriage return
\sspace (represents space, tab, newline or carriage return)
^....$^ starting an expressiong and $ represents ending of the expression
()capturing part
|OR (cats|dogs|birds) - cats or dogs or birds
\bboundary between a word and a non-word character.
Any expression written in CAPITAL LETTER represents opposite of actual definition
ex: \D - non digits
\W - non alphanumeric
\S - non whitespace
Referencing any captured groups using parenthesis('()')
--- there can be many groups clubbed together and to refer each group use
ex: (\d*\.([,\d*]?))*$
\0 - full matched text
\1 - group 1
\2 - group 2

One thought on “Regular expression reference

Leave a Reply

Your email address will not be published. Required fields are marked *