Regex snippets
Line
^ = line start
$ = line end
Text between brackets
\(.*?\)
\(= escape left parenthesis.*?= match all.= any character*= any number of times (0 or more, as opposed to+for 1 or more)?= optionally (i.e. catch the instances in which there is nothing between brackets)
\)= escape right parenthesis
Single character
Wildcard
.= match any single character.\w= match any single alphanumeric character: 0-9, a-z, A-Z, and _ (underscore).\d= match any single digit.\s= match any single whitespace character.
Example regex: a.c
abc // match
a c // match
azc // match
ac // no match
abbc // no match
Optionally
? = match 0 or 1 occurrences of a character
Example regex: a.?c
abc // match
a c // match
azc // match
ac // match
abbc // no match
In a set
Use square brackets [] to match any characters in a set.
Example 1 regex: a[bcd]c
abc // match
acc // match
adc // match
ac // no match
abbc // no match
Example 2 regex: a[0-7]c
a0c // match
a3c // match
a7c // match
a8c // no match
ac // no match
a55c // no match
Except
[^] = match any single character except for any of the characters that come after the chevron ^.
Example regex: a[^abc]c
aac // no match
abc // no match
acc // no match
a c // match
azc // match
ac // no match
azzc // no match
Number of times
{x}wherexis the number of timesa{3}= matchaexactly 3 timesa{6,}= At least 6 occurrences ofaa{,4}= At most 4 occurrences ofa[wxy]{5}= 5 characters, each of which can bew,xory