Skip to content

Common examples of regular expression

Credit card number

\d{4}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}|\d{4}[ -]?\d{6}[ - ]?\d{4}\d?

Email address

/([a-z0-9_\-.+]+)@\w+(\.\w+)*

IP address

\b(?:\d{1,3}\.){3}\d{1,3}\b

Credentials

1234 | admin | password | pass | creds | login

Phone number

(\(?\+?[0-9]{1,2}\)?[-. ]?)?(\(?[0-9]{3}\)?|[0-9]{3})[-. ]?([0-9]{3}[-. ]?[0-9]{4}|\b[A-Z0-9]{7}\b)

Address

(street|st|road|rd|avenue|ave|drive|dr|loop|court|ct|circle|cir|lane|ln|boulevard|blvd|way)\.?\b

Social security number

\b\d{3}[ -.]?\d{2}[ -.]?\d{4}\b

ZIP code

\b\d{5}\b(-\d{4})?\b

URL

([^\s:/?#]+):\/\/([^/?#\s]*)([^?#\s]*)(\?([^#\s]*))?(#([^\s]*))?

Dates

(MM/DD/YYYY)
^([1][12]|[0]?[1-9])[\/-]([3][01]|[12]\d|[0]?[1-9])[\/-](\d{4}|\d{2})$

MD5 hash

^[a-f0-9]{32}$

SHA1 hash

\b([a-f0-9]{40})\b

Base64 encoding

^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$

SQL statements

(LECT\s[\w\*\)\(\,\s]+\sFROM\s[\w]+)|(UPDATE\s[\w]+\sSET\s[\w\,\'\=]+)|(INSERT\sINTO\s[\d\w]+[\s\w\d\)\(\,]*\sVALUES\s\([\d\w\'\,\)]+)

Private IP

(^127\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)

Reference

  • Practical Security Automation and Testing (Tony Hsiang-Chih Hsu)

Disclaimer
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback: dig +short txt issue.imzye.com
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Buy Me a Coffee