Show Menu

The complete RegEx Cheat Sheet by

Anchors (bound­aries)

Start of string or line
End of string or line
Start of input (ignores 'm' flag)
End of input (ignores 'm' flag)
End of the previous match
Word boundary (any position proceeded or followed - but not both - by a letter, digit or unders­core)
Non-word boundary

Character and Sets

Whitespace (Form-­feed, tab, vertic­al-tab, new line, carriage return and space)
[\f\t­\x0b\n\r ]
Hexade­cimal digit
\x00=null; \x0d=\r; [\x61-­\x7­a]=­[a-z]
Octal digit
Any character (except new line \n)


Capture group - captures a set of characters for a later expression
Non-ca­pture group - groups an expression but does not capture. e.g. /((?:f­oo|­fu)­bar)/ matches "­foo­bar­" or "­fub­ar" without "­foo­" or "­fu" appearing as a captured subpattern
Lookahead - match on the characters following. e.g. /ab(?=c)/ match "­ab" only when followed by "­c"
Negative lookahead - match on characters that aren't following. e.g. /ab(?!c)/ match "­ab" only when NOT followed by "­c"
Positive look-b­ehind assertion. e.g. /(?<=f­oo)bar/ matches "­bar­" when preceded by "­foo­"
Negative look-b­ehind assertion. e.g. /(?<!f­oo)bar/ - matches "­bar­" when not preceded by "­foo­"
Comment e.g. (?# This comment is ignored entirely)

Unicode character support

Unicode hexade­cimal character set
ASCII hexade­cimal character set
Control characters
Unicode is not fully supported on all platforms. JavaScript prior to ES6 for example allows ASCII hex but not full Unicode hex.

Special Characters

New line
Carriage return
Vertical tab
Form feed


Zero or more
One or more
Zero or One (i.e. optional)
Exactly 'n' (any number)
Minimum ('n' or more)
Range ('n' or more, but less or equal to 'm')

Flags (expre­ssion modifiers)

Milti-­line. (Makes ^ and $ match the start and end of a line respec­tively)
Treat input as a single line. (Makes '.' match new lines as well)
Case insens­itive pattern matching.
Global matching. (Don't stop after first match in a replac­ement function)
Extended matching. (disregard white-­space not explicitly escaped, and allow comments starting with #)

Escape Characters

In regular expres­sions, the following characters have special meaning and must be escaped:
^ $ [ { ( ) < > . * \ + | ?

Additi­onally the hyphen (-) and close square bracket (]) must be escaped when in an expression set (

/\(\d{3}\) \d{4}[\- ]\d{4}/
matches "­(nnn) nnnn-n­nnn­" or "­(nnn) nnnn nnnn" (where n is a numeric digit).


Greetings, and thanks for providing this.

Where can I find a comprehensive, accessible textual reference on this topic that includes numerous examples? Instead of pursuing blind trial and error, I would like to understand thoroughly what I am doing, and why.


Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Regular Expressions Cheat Sheet
          python regex(regular expression) Cheat Sheet

          More Cheat Sheets by doublehelix

          Ubuntu 18.04 Server Configuration Cheat Sheet
          Python Date Time Format (strftime) Cheat Sheet