-
Simple characters
abc
-
Quantifiers
*0 or more+1 or more?0 or 1{2}exactly 2{2-4}2, 3 or 4{2,}2 or more
-
More characters
.wildcard, any character except line break\da digit,\Dnot a digit\wword character,\Wnot a word character\swhitespace character,\Snot a whitespace charactera|blogical OR
-
Character classes
[abc]character classes[a-zA-Z]ranged character class[^abc]negated character class
-
Anchors (zero length)
^start of line$end of line\bword boundary\astart of string\zend of string (including trailing\n)\Zend of string (excluding trailing\n)
-
Capture groups
(abc)standard capture group(?:abc)non capturing group\1,\2captured groups- Ordered by the open brackets
-
Look arounds
a(?=b)positive lookahead, match anathat is followed by ab(but don't match theb)a(?!b)negative lookahead, match anathat is NOT followed by ab(but don't match what follows thea)(?<=a)bpositive lookbehind, match abthat is proceeded by aa(but don't match thea)(?<!a)bnegative lookbehind, match abthat is NOT proceeded by aa(but don't match what proceeds theb)
-
Modifiers
- Case-insensitivity (
/i), global (/g), multiline (/m), etc. - There are more (ungreedy, line endings, etc.)
- Often better to look at the tool/language as they vary a lot (
/i,(?i), etc.)
- Case-insensitivity (
-
Tools
- http://rubular.com/
- http://regexr.com/
- http://emailregex.com/
- vim (with
:set hls) - Remember some tools need some symbols escaped!
Last active
February 1, 2018 17:51
-
-
Save stevenocchipinti/57711d2d61333416976ed7d67b832949 to your computer and use it in GitHub Desktop.
Regex
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment