Regex - auto-mate/CheatSheetWiki GitHub Wiki
Regex
For more info and testing see regex101.com
Basics
-
Characters
1 matches 1
. any character -
Quantifiers - How many Times to Match
* matches preceding char/group "0" or more times
+ matches preceding char/group "1" or more times
? matches preceding char/group "0" or "1" times
{4} matches preceding char/group 4 times
{4,} matches preceding char/group 4 or MORE times
{4,6} matches preceding char/group 4 to 6 times -
Escape Character
\ escape e.g. if you want to match * -
Anchors
^ beginning of line
$ end of line -
Groups
[] any item inside once
[e-s] lowercase e-s once
[a-zA-Z] all letters once
[a-zA-Z0-9] all letters and numbers once
[a-zA-Z0-9]{4} all letters and numbers 4 times e.g. 1aff AB12 AAAA eeee etc
[a-z&] one of all lowercase letters and & once
Special Commands
New Line \n
Tab \t
Null \0
Whitespace \s
NON Whitespace \S
Digit \d
NON Digit \D
Word Character \w
NON Word Character \W
Hex 2 \xYY
Hex 4 \xYYYY
[:alnum:](/auto-mate/CheatSheetWiki/wiki/:alnum:)
[:alpha:](/auto-mate/CheatSheetWiki/wiki/:alpha:)
[:ascii:](/auto-mate/CheatSheetWiki/wiki/:ascii:)
[:blank:](/auto-mate/CheatSheetWiki/wiki/:blank:)
[:cntrl:](/auto-mate/CheatSheetWiki/wiki/:cntrl:)
[:digit:](/auto-mate/CheatSheetWiki/wiki/:digit:)
[:graph:](/auto-mate/CheatSheetWiki/wiki/:graph:) - visible
[:lower:](/auto-mate/CheatSheetWiki/wiki/:lower:)
[:print:](/auto-mate/CheatSheetWiki/wiki/:print:)
[:punct:](/auto-mate/CheatSheetWiki/wiki/:punct:)
[:space:](/auto-mate/CheatSheetWiki/wiki/:space:)
[:upper:](/auto-mate/CheatSheetWiki/wiki/:upper:)
[:word:](/auto-mate/CheatSheetWiki/wiki/:word:)
[:xdigit:](/auto-mate/CheatSheetWiki/wiki/:xdigit:) - hex
[:<:](/auto-mate/CheatSheetWiki/wiki/:<:) - word start
[:>:](/auto-mate/CheatSheetWiki/wiki/:>:) - word end
Lookahead Behind
- Ahead
foo(?=bar) matches foo in foobar but not in foodoo
foo(?!bar) matches foo in foodoo but not in foobar - Behind
(?<=foo)bar matches bar in foobar but not in fuubar
(?<!foo )bar matches bar in fuubar but not in foobar
Logical
a|b matches a or b
(foo)|(fu{2}) matches foo and fuu in foobar fuubar