Skip to content

Instantly share code, notes, and snippets.

@abdorah
Created December 2, 2021 12:42
Show Gist options
  • Save abdorah/f826d4f60b0b1d19272b7035fc0a38cd to your computer and use it in GitHub Desktop.
Save abdorah/f826d4f60b0b1d19272b7035fc0a38cd to your computer and use it in GitHub Desktop.
Memento about RegEx

Regex Reference

Basics

  • / expression / flags, i.e /[A-Z]+/g basic format
  • / hello\?\*\\/ escape special characters with backslashes
  • () group with parentheses
  • | logical OR

Character classes

  • \w word \d digit \s whitespace (tabs, line breaks)
  • \W NOT word \D NOT digit \S NOT whitespace
  • \t tabs, \n line breaks
  • . any character (except newline)

Brackets

  • [xyz] match any x, y, z
  • [J-Z] match any capital letters between J & Z.
  • [^xyz] NOT x, y, z

Quantification

  • bob|alice match bob or alice
  • z? zero or one occurrences
  • z* zero or multiple occurrences
  • z+ one or multiple occurrences
  • z{n} n occurrences
  • z{min,max} min/max occurrences

Anchors

  • hello world exact match
  • ^hello start of the strings
  • world$ end of the string
@abdorah
Copy link
Author

abdorah commented Dec 2, 2021

If you were interested in practicing you can use this wonderful website:
https://regexr.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment