Frequently Used Regex Patterns

Regex expressions are used frequently in searching or validating different formats. The followings are frequently used regex patterns.

Email Validation Pattern

Regex pattern ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$ matches a valid email address.

/ /g

URL Validation Pattern

Regex pattern ^(https?:\/\/)?([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5})(:[0-9]{1,5})?(\/.*)?$ matches a valid URL starting with http or https.

/ /g

Numeric Input Validation Pattern

Regex pattern ^\d+(?:\.\d+)?$ validates numeric input, including both decimal and integer values.

/ /g

Date Validation Pattern (YYYY-MM-DD)

Regex pattern ^(?:19|20)\d\d-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])$ matches a valid date in YYYY-MM-DD format.

/ /g

Time Validation Pattern (HH:MM AM/PM)

Regex pattern ^(1[0-2]|0?[1-9]):[0-5][0-9] (AM|PM)$ matches a time in 12-hour format with optional AM/PM designation.

/ /g

Phone Number Validation Pattern

Regex pattern ^\+?[1-9]\d{1,14}$ validates a phone number, allowing an optional "+" sign at the beginning.

/ /g

Zip Code Validation Pattern (US)

Regex pattern ^\d{5}(?:[-\s]\d{4})?$ matches a US ZIP code, with or without the optional ZIP+4 format.

/ /g

Password Strength Validation Pattern

Regex pattern ^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[^\w\s]).{8,}$ validates a password with the following criteria: at least one uppercase letter, one lowercase letter, one digit, one special character, and a minimum length of 8 characters.

/ /g

File Extension Validation Pattern

Regex pattern ^.+\.(jpg|jpeg|png|gif|pdf)$ matches common image and document file extensions (jpg, jpeg, png, gif, pdf).

/ /g

IP Address Validation Pattern

Regex pattern ^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$ matches a valid IPv4 address in xxx.xxx.xxx.xxx format that includes four groups of numbers separated by dots and each group can range from 0 to 255.

/ /g