-
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\d
a digit,\D
not a digit\w
word character,\W
not a word character\s
whitespace character,\S
not a whitespace charactera|b
logical 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\b
word boundary\a
start of string\z
end of string (including trailing\n
)\Z
end of string (excluding trailing\n
)
-
Capture groups
(abc)
standard capture group(?:abc)
non capturing group\1
,\2
captured groups- Ordered by the open brackets
-
Look arounds
a(?=b)
positive lookahead, match ana
that is followed by ab
(but don't match theb
)a(?!b)
negative lookahead, match ana
that is NOT followed by ab
(but don't match what follows thea
)(?<=a)b
positive lookbehind, match ab
that is proceeded by aa
(but don't match thea
)(?<!a)b
negative lookbehind, match ab
that 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