Skip to content

Instantly share code, notes, and snippets.

@jeromecovington
Last active August 28, 2020 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeromecovington/75d23cebb22316962fa0d8360ba29c70 to your computer and use it in GitHub Desktop.
Save jeromecovington/75d23cebb22316962fa0d8360ba29c70 to your computer and use it in GitHub Desktop.
Matchers
^
Match starting position
.
Match any single character, enclose in bracket for literal dot
a.c -> "abc", etc.
[a.c] -> "a", ".", "c"
[ ]
Match single character, or character within range
[abc], [a-c] -> "a", "b", "c"
[a-cx-z] -> "a", "b", "c", "x", "y", "z"
[^ ]
Match single character not contained in brackets
[^a-y] -> "z", etc.
$
Match ending position
( )
Subexpression, can be recalled later with $1, $2, etc.
\n
Matches whatever nth marked subexpression matched.
*
Matches preceding element zero or more times
12* -> "1", "12", "122", etc.
[ab]* -> "", "a", "aa", "ab", "abb", etc.
(ab)* -> "", "ab", "abab", "ababab", etc.
{m,n}
Matches preceding element at least m but not more than n times
a{2,5} -> "aa", "aaa", "aaaa", "aaaaa"
?
Matches preceding element zero or one time
ab?c -> "ac", "abc"
+
Matches preceding element one or more times
ab+c -> "abc", "abbc", "abbbc", etc.
|
Choice
abc|xyz -> "abc" or "xyz"
Character Classes
\w
[A-Za-z0-9_]
\W
[^A-Za-z0-9_]
\d
[0-9]
\D
[^0-9]
\s
[ \t\r\n\v\f] white-space
\S
[^ \t\r\n\v\f] non white-space
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment