Regex for Beginners: 10 Patterns You’ll Actually Use

Regular expressions look scary but follow a few simple rules. These are the patterns people reach for most.

🧪Free Regex Tester
Test regular expressions with live highlighting.
Open tool →

The building blocks

\d digit, \w letter/digit/underscore, \s whitespace, . any character, + one or more, * zero or more, ? optional, {2,4} two to four, ^ start, $ end, [abc] any of a/b/c, (…) a group, | or.

10 handy patterns

Simple email: [\w.+-]+@[\w-]+\.[\w.]+ · US phone: \(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4} · Date YYYY-MM-DD: \d{4}-\d{2}-\d{2} · URL: https?://\S+ · Hex colour: #[0-9a-fA-F]{6} · Extra spaces: \s{2,} · Trailing spaces: [ \t]+$ · Digits only: ^\d+$ · Words: \b\w+\b · HTML tags: <[^>]+>

Flags

g finds all matches, i ignores case, m makes ^ and $ work per line, s lets . match line breaks.

Test before you use it

Paste the pattern and some sample text into the Regex Tester – every match and capture group is highlighted live, so you catch mistakes before they hit real data.

Frequently asked questions

Can regex validate emails perfectly?

No – use a simple pattern, then confirm by sending an email.

Why does my pattern match too much?

Use lazy quantifiers like +? or be more specific than .

Which regex flavour is this?

JavaScript; most patterns work the same in Python and PHP.

🧪Free Regex Tester
Test regular expressions with live highlighting.
Open tool →

More guides