Try our new free AI stock portfolio analyzer!
Protoolio Logo

Regex Cheatsheet

Explore a collection of 20 commonly used regular expressions for various purposes, such as matching email addresses, dates, HTML tags, and more.

Match Email Addresses:

This regex matches valid email addresses.

/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b/

Match Dates (YYYY-MM-DD):

This regex matches dates in the format YYYY-MM-DD.

/\d{4}-\d{2}-\d{2}/

Match HTML Tags:

This regex matches HTML tags, both opening and closing, as well as self-closing tags.

/<([A-Za-z][A-Za-z0-9]*)\b[^>]*>.*?<\/\1>|<.*? \/>/

Match IP Addresses:

This regex matches valid IPv4 addresses.

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

Match URLs:

This regex matches URLs starting with "http://" or "https://" or "ftp://".

/(https?|ftp):\/\/[^\s/$.?#].[^\s]*

Match Phone Numbers (US Format):

This regex matches US phone numbers in various formats.

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

Match Social Security Numbers (SSN):

This regex matches Social Security Numbers in the format 123-45-6789.

/^\d{3}-\d{2}-\d{4}$/

Match Credit Card Numbers:

This regex matches credit card numbers.

/\b(?:\d[ -]*?){13,16}\b/

Match Hexadecimal Color Codes:

This regex matches hexadecimal color codes, with or without the leading #.

/^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/

Match Only Alphabetic Characters:

This regex matches strings containing only alphabetic characters.

/^[A-Za-z]+$/

Match Only Numeric Characters:

This regex matches strings containing only numeric characters.

/^\d+$/

Match Alphanumeric Characters:

This regex matches strings containing only alphanumeric characters.

/^[A-Za-z0-9]+$/

Match Whitespace Characters:

This regex matches any whitespace character (space, tab, newline).

/\s/

Match Non-Whitespace Characters:

This regex matches any non-whitespace character.

/\S/

Match Word Characters:

This regex matches any word character (alphanumeric + underscore).

/\w/

Match Non-Word Characters:

This regex matches any non-word character.

/\W/

Match One or More Occurrences:

This regex matches one or more occurrences of the pattern.

/pattern+/

Match Zero or More Occurrences:

This regex matches zero or more occurrences of the pattern.

/pattern*/

Match Exactly 'n' Occurrences:

This regex matches exactly 'n' occurrences of the pattern.

/pattern{n}/

Match Range of Occurrences (m to n):

This regex matches a range of 'm' to 'n' occurrences of the pattern.

/pattern{m,n}/
New on Protoolio

Free AI Stock Portfolio Analyzer

Assess and optimize your stock portfolio with personalized insights and recommendations to maximize your returns and minimize risks.