Skip to content

Instantly share code, notes, and snippets.

@ojroques
Last active May 14, 2021 17:07
Show Gist options
  • Save ojroques/072b81366d7e5bbf2f1dc7e21a809973 to your computer and use it in GitHub Desktop.
Save ojroques/072b81366d7e5bbf2f1dc7e21a809973 to your computer and use it in GitHub Desktop.
regex cheatsheet

REGEX cheatsheet

From regexone.com and regexr.com.

Contents

Character Classes

Expression Pattern
abc... Letters
123... Digits
[abc] Any character in the set
[^abc] Any character not in the set
[a-z] Characters having a code between the two specified characters (inclusive)
. Any character
\w Any alphanumeric (A-Z, a-z, 0-9) character
\W Any non-alphanumeric character
\d Any digit
\D Any non-digit characters
\s Any whitespace (spaces, tabs, line breaks)
\S Any non-whitespace character

Positions

Expression Pattern
^ Start of the string
$ End of the string
\b Boundary between a word character and non-word character
\B Any position that is not a word boundary

Quantifiers

Expression Pattern
* Zero or more repetitions
+ One or more repetitions
? Optional character
{m} m repetitions
{m,} m or more repetitions
{m, n} m to n repetitions
(abc|def) abc or def

Escaped Characters

Expression Pattern
\+ Character with special meaning
\xFF Character in hexadecimal form
\t Tab character
\n Line feed character
\r Carriage return character
\0 Null character

Capture Groups

Expression Pattern
(abc) Capture group
\1 Result of a capture group
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment