Skip to content

Instantly share code, notes, and snippets.

@WilliamPourmajidi
Last active January 27, 2021 15:39
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 WilliamPourmajidi/678c59c5d2ddf6538fdda0bda101a472 to your computer and use it in GitHub Desktop.
Save WilliamPourmajidi/678c59c5d2ddf6538fdda0bda101a472 to your computer and use it in GitHub Desktop.
Regular Expressions
# Regular Expressions
. - Any Character Except New Line
\d - Digit (0-9)
\D - Not a Digit (0-9)
\w - Word Character (a-z, A-Z, 0-9, _)
\W - Not a Word Character
\s - Whitespace (space, tab, newline)
\S - Not Whitespace (space, tab, newline)
\b - Word Boundary
\B - Not a Word Boundary
^ - Beginning of a String
$ - End of a String
[] - Matches Characters in brackets
[^ ] - Matches Characters NOT in brackets
| - Either Or
( ) - Group
Quantifiers:
* - 0 or More
+ - 1 or More
? - 0 or One
{3} - Exact Number
{3,4} - Range of Numbers (Minimum, Maximum)
------------------------------------E X A M P L E S --------------------------------------
regex = [A-Za-z0-9\.+_-~-]+@[A-Za-z.]+\.[A-Za-z]{2,3}
read it as: check for 1 or more of [A-Za-z0-9\.+_-~-] followed by an @ and then following by 1 or more of [A-Za-z.] following by a dot and then 2 or 3 characters of [A-Za-z]
Internet email addresses must include only RFC-compliant characters, which include:
Numbers 0-9.
Uppercase letters A-Z.
Lowercase letters a-z.
Plus sign +
Hyphen -
Underscore _
Tilde ~
Valid Emails
william@test.com
william.pourmajidi@gmail.com
william+pourmajidi@gmail.com
william-pourmajidi@gmail.com
william_pourmajidi@gmail.com
william~pourmajidi@gmail.com
william@gmail.com
william@gmail.ai
william.1982@gmail.com
1982.william@gmail.com
william.pourmajidi@subdomain.gmail.com
Invalid Emails
william.pourmajidi.gmail.com
william@gmail
william@gmail.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment