Skip to content

Instantly share code, notes, and snippets.

@CalamityAdam
Created May 6, 2022 20:55
Show Gist options
  • Save CalamityAdam/f22055086935142ce70256c7498e0865 to your computer and use it in GitHub Desktop.
Save CalamityAdam/f22055086935142ce70256c7498e0865 to your computer and use it in GitHub Desktop.
Regular Expression Cheatsheet
character description example
. Wildcard - matches any character /c.t/.test('cat'); => true
/./.test(''); => false
^ Boundary - beginning of string /^big/.test('big dog'); => true
/^c/.test('abc'); => false
$ Boundary - end of string /dog$/.test('big dog'); => true
/a$/.test('abc'); => false
+ Character occurs 1 or more times /ca+t/.test('caaat'); => true
/ab+c/.test('ac'); => false
* Character occurs 0 or more times /ca*t/.test('ct'); => true
/a*/.test(''); => true
| Or (this or that) /a|b/.test('b'); => true
/at|og/.test('dog'); => true
\x Hex codes (\x and then 2 digits, i.e. \x21 == '!') /\x41/.test('a'); => true
( ) Parens - groups logic together /(^a)|(^b)/.test('ax'); => true
\ Escape
\d Numbers (0-9)
\s Whitespace (spaces, newlines, tabs, etc.
\t Tab character
\D Negates lowercase version (no numbers)
\S Negates lowercase version (non-whitespace)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment