Skip to content

Instantly share code, notes, and snippets.

@fr3fou
Last active July 1, 2018 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fr3fou/2ea606e8b54df7b8c9f9a891e4578f49 to your computer and use it in GitHub Desktop.
Save fr3fou/2ea606e8b54df7b8c9f9a891e4578f49 to your computer and use it in GitHub Desktop.

REGEX

[0-9]+ matches non-empty sequence of digits
[A-Z][a-z]* matches a capital + small letters
\s+ matches whitespace (non-empty)
\S+ matches non-whitespace

[nvj] matches any character that is either n, v or j
[^abc] – matches any character that is not a, b or c
[0-9] – character range: matches any digit from 0 to 9

\w – matches any word character (a-z, A-Z, 0-9, _)

\W – matches any non-word character (the opposite of \w)

\s – matches any white-space character
\S – matches any non-white-space character (opposite of \s)
\d – matches any decimal digit
\D – matches any non-decimal digit (opposite of \d)

* – matches the previous element zero or more times

+ – matches the previous element one or more times

? – matches the previous element zero or one time

{3} – matches the previous element exactly 3 times

^ – the match must start at the beginning of the text or line
$ – the match must occur at the end of the text or line
Use multiline matching (/m flag) to match the end of line

(subexpression) – captures the matched subexpression as numbered group

(?:subexpression) – defines a non-capturing group

(?<name>subexpression) – defines a named capturing group

Shoutout to SonnyRR

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