Skip to content

Instantly share code, notes, and snippets.

@Sasha-hk
Last active April 16, 2022 16:33
Show Gist options
  • Save Sasha-hk/ebf57dabdc8eb363324c40ef2570a7ae to your computer and use it in GitHub Desktop.
Save Sasha-hk/ebf57dabdc8eb363324c40ef2570a7ae to your computer and use it in GitHub Desktop.

Regular expressions

Syntax example:

/expression/

Good resource to training skills in regular expressions regexr.com or regex101.com

Special symbols:

  • \w - letters with numbers
  • \W - special symbols
  • \d - digits
  • \D - not digits
  • \s - space
  • \S - not spaces
  • ^ - start of the line
  • $ - end of the line
  • (x|y) - this or this
  • [1-9] - range
  • [^1] - denial (all except 1)
  • \w+ - letters from 1 to infinity
  • \w{1,10} - from 1 to 10 letters
  • and others

Example

Match email:

/^\w+@\w+.\w+/

Match phone number:

/^\+\d{2,3}\s\d{3}\s\d{3}\s\d{1,3}/

Find file name with .js or .ts extension:

/\w+\.(j|t)s/

Set range for numbers:

/[0-9]/

Except 'w' letter:

/([^w])/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment