Created
November 19, 2011 03:54
-
-
Save leesmith/1378416 to your computer and use it in GitHub Desktop.
Regex cheatsheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
regex characters: | |
. | |
any character except newline | |
[ ] | |
any single character of set | |
[^ ] | |
any single character NOT of set | |
* | |
0 or more previous regular expression | |
*? | |
0 or more previous regular expression (non-greedy) | |
+ | |
1 or more previous regular expression | |
+? | |
1 or more previous regular expression (non-greedy) | |
? | |
0 or 1 previous regular expression | |
| | |
alternation | |
( ) | |
grouping regular expressions | |
^ | |
beginning of a line or string | |
$ | |
end of a line or string | |
{m,n} | |
at least m but most n previous regular expression | |
{m,n}? | |
at least m but most n previous regular expression (non-greedy) | |
\1-9 | |
nth previous captured group | |
\& | |
whole match | |
\` | |
pre-match | |
\' | |
post-match | |
\+ | |
highest group matched | |
\A | |
beginning of a string | |
\b | |
backspace(0x08)(inside[]only) | |
\b | |
word boundary(outside[]only) | |
\B | |
non-word boundary | |
\d | |
digit, same as[0-9] | |
\D | |
non-digit | |
\S | |
non-whitespace character | |
\s | |
whitespace character[ \t\n\r\f] | |
\W | |
non-word character | |
\w | |
word character[0-9A-Za-z_] | |
\z | |
end of a string | |
\Z | |
end of a string, or before newline at the end | |
(?#) | |
comment | |
(?:) | |
grouping without backreferences | |
(?=) | |
zero-width positive look-ahead assertion | |
(?!) | |
zero-width negative look-ahead assertion | |
(?>) | |
nested anchored sub-regexp. stops backtracking. | |
(?imx-imx) | |
turns on/off imx options for rest of regexp. | |
(?imx-imx:re) | |
turns on/off imx options, localized in group. | |
special character classes: | |
[:alnum:] | |
alpha-numeric characters | |
[:alpha:] | |
alphabetic characters | |
[:blank:] | |
whitespace - does not include tabs, carriage returns, etc | |
[:cntrl:] | |
control characters | |
[:digit:] | |
decimal digits | |
[:graph:] | |
graph characters | |
[:lower:] | |
lower case characters | |
[:print:] | |
printable characters | |
[:punct:] | |
punctuation characters | |
[:space:] | |
whitespace, including tabs, carriage returns, etc | |
[:upper:] | |
upper case characters | |
[:xdigit:] | |
hexadecimal digits | |
options: | |
/i | |
case insensitive | |
/o | |
only interpolate #{} blocks once | |
/m | |
multiline mode - '.' will match newline | |
/x | |
extended mode - whitespace is ignored | |
/[neus] | |
encoding: none, EUC, UTF-8, SJIS, respectively |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment