regexp cheatsheet

Character classes

.Any character, except newline
\wWord
\dDigit
\sWhitespace
\WNot word
\DNot digit
\SNot whitespace
[abc]Any of a, b, or c
[a-e]Characters between a and e
[1-9]Digit between 1 and 9
[^abc]Any character except ab or c

Anchors

^abcStart with abc
abc$End with abc

Escaped characters

\. \* \\Escape special character used by regex
\tTab
\nNewline
\rCarriage return

Groups

(abc)Capture group

Quantifiers

a*Match 0 or more
a+Match 1 or more
a?Match 0 or 1
a{5}Match exactly 5
a{,3}Match up to 3
a{3,}Match 3 or more
a{1,3}Match between 1 and 3
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *