RUNWEBTOOLS
English
Web & Developer

Regular Expressions for Beginners: A Gentle Introduction

Updated 2026-07-06

Regular expressions have a reputation for being cryptic — a wall of symbols like ^\\d{3}-\\d{4}$. But the core idea is simple, and a little regex is one of the highest-leverage skills for anyone who works with text. This guide starts from zero.

What a regular expression is

A regular expression (regex) is a pattern that describes a set of strings. Instead of searching for one exact word, you describe the shapeof what you're looking for — “three digits, a dash, then four digits” — and the engine finds every piece of text that fits. It's used for search-and-replace, validating input (emails, phone numbers), and pulling data out of text.

Literal characters

The simplest regex is just text. The pattern cat matches the letters c-a-t anywhere in the input. Most characters match themselves — the power comes from a handful of special ones.

The core building blocks

Character classes — what kind of character

  • \\d — any digit; \\w — a word character; \\s — whitespace.
  • . — any character at all.
  • [aeiou] — any one character from the set; [a-z] — a range.

Quantifiers — how many

  • * — zero or more; + — one or more; ? — zero or one (optional).
  • {3} — exactly three; {2,4} — between two and four.

Anchors — where

  • ^ — start of the string; $ — end of the string.

Reading a real example

Now that wall of symbols from the intro makes sense:

^\d{3}-\d{4}$
^      start of string
\d{3}  exactly three digits
-      a literal dash
\d{4}  exactly four digits
$      end of string

It matches a string that is only a 7-digit phone number like 555-1234 — nothing before, nothing after.

Don't forget to escape

To match a character that's normally special — a literal dot or question mark — put a backslash before it: \\. matches a real dot. Forgetting this is the number-one beginner mistake, because . otherwise matches any character.

Keep practicing

The fastest way to learn is to try patterns against real text and watch what matches. Keep the regex cheat sheet open as you go, and use tools like find and replace to apply patterns to your own text. Once regex clicks, tasks that felt tedious — reformatting a list, extracting every URL, validating input — become one-liners.

More in Web & Developer

See all Web & Developer guides →

Tools mentioned in this guide