Developer Tools2026-04-128 min read

Learn Regular Expressions: From Zero to Useful in 20 Minutes

Regex is the punctuation-heavy syntax that every developer encounters but nobody enjoys learning. It looks like line noise. But once you understand a few core concepts, regex becomes a superpower for text processing. Here is the guide I wish I had when starting out.

Building Blocks

Character classes: [a-z] matches any lowercase letter. [0-9] matches any digit. [aeiou] matches vowels. Combine them: [a-zA-Z0-9] matches any alphanumeric character.

Quantifiers: * means zero or more. + means one or more. ? means optional (zero or one). {n} means exactly n times. {n,m} means between n and m times.

Anchors: ^ matches start of line. $ matches end of line. \b matches a word boundary.

Groups and Alternation: (cat|dog) matches either "cat" or "dog". Parentheses also create capture groups that you can reference later with \1, \2, etc.

Real-World Patterns

Email (basic): [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}. This catches most email formats. Production email validation should also check MX records, not rely on regex alone.

Phone (US): \(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}. Handles (555) 123-4567, 555-123-4567, 555.123.4567, and 5551234567.

Date (YYYY-MM-DD): \d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]). Validates ISO 8601 dates.

Test Before You Ship

Our Regex Tester lets you write patterns and see matches highlighted in real time. Paste your test data, write the regex, and verify it matches what you expect — and does NOT match what it should not. Negative testing (checking what your pattern should reject) is just as important as positive testing.

This article was written by UnTrackedTools founder Alex Chen, based on real debugging experience with production regex patterns.

About UnTrackedTools Blog: All guides are written from personal experience using our tools — every tip, every number comes from real testing and use.