Skip to content

Instantly share code, notes, and snippets.

@lucalves
Last active June 22, 2022 17:57
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 lucalves/862ec260b729da2839095ab2d8143cb5 to your computer and use it in GitHub Desktop.
Save lucalves/862ec260b729da2839095ab2d8143cb5 to your computer and use it in GitHub Desktop.
List of most common REGEX expressions (validated)

Use https://regex101.com/ to validate the expressions.

  1. Simple numbers only (no decimal and no fractions)
^(\d+)$
  1. Decimal numbers
^(\d*)[.,](\d+)$
  1. Alphanumeric without spaces
^(\w*)$
  1. Email (simple — see advanced section for more)
^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6})*$
  1. Email tokens
^([a-z0-9_\.\+-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$
  1. Valid email (RFC5322)
\b[\w.!#$%&’*+\/=?^`{|}~-]+@[\w-]+(?:\.[\w-]+)*\b
  1. Username (simple)

Minimum length of 3, maximum length of 16, composed by letters, numbers or dashes.

/^[a-z0-9_-]{3,16}$/
  1. Strong password

Minimum length of 6, at least 1 uppercase letter, at least 1 lowercase letter, at least 1 number, at least 1 special character

(?=^.{6,}$)((?=.*\w)(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[|!"$%&\/\(\)\?\^\'\\\+\-\*]))^.*
  1. SSN — Social Security Number (simple)

If you want to check the validity of an SSN.

^((?<area>[\d]{3})[-][\d]{2}[-][\d]{4})$
  1. URL or IPv4 address
^(((h..ps?|f.p):\/\/)?(?:([\w\-\.])+(\[?\.\]?)([\w]){2,4}|(?:(?:25[0–5]|2[0–4]\d|[01]?\d\d?)\[?\.\]?){3}(?:25[0–5]|2[0–4]\d|[01]?\d\d?)))*([\w\/+=%&_\.~?\-]*)$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment