DEV Community

楊東霖
楊東霖

Posted on • Originally published at devtoolkit.cc

The Complete Guide to Regular Expressions in 2026

Regular expressions — regex — are one of the most powerful tools in a developer's toolkit. They're also one of the most intimidating. But regex is genuinely worth learning.

The Basic Building Blocks

Character Classes

/[abc]/     // matches 'a', 'b', or 'c'
/[0-9]/     // matches any digit (same as \d)
/[a-z]/     // matches any lowercase letter
Enter fullscreen mode Exit fullscreen mode

Quantifiers

/\d+/       // 1 or more digits
/\w{3}/     // exactly 3 word characters
/https?/    // matches "http" or "https"
Enter fullscreen mode Exit fullscreen mode

Real-World Examples

Email Validation

/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
Enter fullscreen mode Exit fullscreen mode

Password Strength

// At least 8 chars, 1 uppercase, 1 lowercase, 1 number, 1 special char
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/
Enter fullscreen mode Exit fullscreen mode

Lookahead and Lookbehind

Match something based on what comes before or after it:

/\d+(?=\$)/    // match digits only when followed by $
// "100 dollars and 50$" → matches "50"
/(?<=\$)\d+/     // match digits only when preceded by $
Enter fullscreen mode Exit fullscreen mode

The best developers use regex as a precision tool — start simple, build up complexity, and test every pattern before deploying it.

Try our Regex Tester to experiment with patterns instantly.

Free Developer Tools

If you found this article helpful, check out DevToolkit — 40+ free browser-based developer tools with no signup required.

Popular tools: JSON Formatter · Regex Tester · JWT Decoder · Base64 Encoder

🛒 Get the DevToolkit Starter Kit on Gumroad — source code, deployment guide, and customization templates.

Top comments (0)