REGEX FOR BEGINNERS โ€” LEARN REGULAR EXPRESSIONS
A beginner-friendly guide to regular expressions. Learn patterns, quantifiers, character classes, groups, and real-world examples.
๐Ÿ“– 12 min read ยท Dev ยท Free guide by 67fresh.com
In this guide
What is Regex?Basic PatternsQuantifiersCharacter ClassesGroups & AlternationAnchorsReal-World ExamplesPractice Exercises
โŒฅ Regex Testerโ‡„ Diff Checker{ } JSON FormatterโŠŸ Base64 Encoder

What is Regex?

A regular expression (regex) is a sequence of characters that defines a search pattern. Think of it as a powerful "find" tool that can match not just exact text, but patterns of text โ€” like "any email address" or "all phone numbers in this document."

Regex is used everywhere: form validation, search-and-replace in code editors, log file analysis, data extraction, and web scraping. Learning regex is one of the highest-leverage skills for developers, data analysts, and power users.

Basic Patterns

At its simplest, a regex is just literal text. The pattern hello matches the word "hello" anywhere in a string. But regex becomes powerful with special characters:

Quantifiers โ€” How Many?

Quantifiers specify how many of the preceding element to match:

Character Classes

Square brackets define a set of characters to match:

Groups & Alternation

Parentheses create groups that can be captured and reused:

Capture groups are one of regex's superpowers. In search-and-replace, you can reference them with $1, $2, etc. to restructure text.

Anchors โ€” Where to Match

Real-World Examples

Email Validation

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

Matches most standard email addresses like user@example.com.

Phone Numbers (US)

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

Matches: (555) 123-4567, 555-123-4567, 5551234567, 555.123.4567

URLs

https?:\/\/[\w.-]+\.[a-z]{2,}[\/\w.-]*

Matches most HTTP and HTTPS URLs.

IP Addresses

\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b

Dates (MM/DD/YYYY)

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

Practice Exercises

Try these in the 67Fresh Regex Tester:

  1. Write a pattern to match all words starting with a capital letter
  2. Match prices like $9.99, $100.00, $1,299.50
  3. Extract all hashtags from a tweet (#word pattern)
  4. Match hex color codes (#FFF or #FF00AA)
  5. Validate a password: 8+ chars, at least one uppercase, one digit
The key to learning regex is practice. Use the regex tester with real text and experiment. Start simple and build up complexity gradually.