AI Generated Cheatsheets

Regular Expressions (Regex) Cheatsheet

Overview

Basic Syntax

Examples

Example 1: Matching an Email Address

// Example regex to match an email address
[\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}

This regex will match an email address in the format username@domain.com.

Example 2: Matching a Phone Number

// Example regex to match a phone number
\+?\d{1,3}[-. ]?\d{3}[-. ]?\d{4}

This regex will match a phone number in a variety of formats, including 123-456-7890, 123.456.7890, and +1 123-456-7890.

Example 3: Matching a URL

// Example regex to match a URL
https?://[\w\-\.]+(:\d+)?(/[\w/_\.]*)?

This regex will match a URL in a variety of formats, including http://www.example.com, https://example.com/path/to/page.html, and http://www.example.com:8080/path/to/page.html.

Special Characters

Character Classes

Quantifiers

Advanced Syntax

Resources