Regex Cheat Sheet

Master regular expressions with this comprehensive cheat sheet. Learn patterns for matching text, numbers, emails, URLs, and more. Perfect for beginners and advanced users.

G
GUi Softworks
8 min read

What is Regex?

Regular expressions (regex) are sequences of characters that define search patterns. They are incredibly powerful for finding, matching, and manipulating text.

Basic Characters

PatternDescriptionExample
Any character except newlinea.c matches "abc", "a1c"
\dAny digit (0-9)\d\d matches "42"
\DAny non-digit\D+ matches "abc"
\wWord character (a-z, A-Z, 0-9, _)\w+ matches "hello_123"
\WNon-word character\W matches "@", "#"
\sWhitespace (space, tab, newline)\s+ matches " "
\SNon-whitespace\S+ matches "hello"

Quantifiers

PatternDescriptionExample
*0 or moreab*c matches "ac", "abc", "abbc"
+1 or moreab+c matches "abc", "abbc"
?0 or 1 (optional)colou?r matches "color", "colour"
{n}Exactly n times\d{4} matches "2025"
{n,}n or more times\d{2,} matches "42", "123"
{n,m}Between n and m times\d{2,4} matches "42", "123", "2025"

Anchors

PatternDescriptionExample
^Start of string/line^Hello matches "Hello World"
$End of string/lineWorld$ matches "Hello World"
\bWord boundary\bcat\b matches "cat" not "category"
\BNon-word boundary\Bcat matches "category"

Character Classes

PatternDescriptionExample
[abc]Match any of a, b, or c[aeiou] matches vowels
[^abc]Match any except a, b, or c[^0-9] matches non-digits
[a-z]Range: any lowercase letter[a-zA-Z] any letter
[0-9]Range: any digit[0-9]+ matches numbers

Groups and Alternation

PatternDescriptionExample
(abc)Capturing group(\d+)-(\d+) captures both numbers
(?:abc)Non-capturing group(?:https?://) groups without capturing
a|bAlternation (or)cat|dog matches either
\1Backreference to group 1(\w)\1 matches "aa", "bb"

Common Patterns

Email Address

[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}

URL

https?://[\w.-]+(?:/[\w./-]*)?

Phone Number (US)

\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}

Date (YYYY-MM-DD)

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

IP Address (IPv4)

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

Credit Card Number

\b(?:\d{4}[- ]?){3}\d{4}\b

Flags

FlagDescription
iCase-insensitive matching
gGlobal - find all matches
mMultiline - ^ and $ match line starts/ends
sDotall - . matches newlines too

Tips for Using Regex Data Extractor

  1. Start simple and build complexity gradually
  2. Use the preview feature to test your patterns
  3. Escape special characters with backslash when matching literally
  4. Use non-greedy quantifiers (*?, +?) when needed
  5. Test with edge cases to ensure your pattern works correctly

With Regex Data Extractor, you can apply these patterns directly to any webpage and extract exactly the data you need. Happy extracting!

regexcheat sheetpatternstutorial