FTJ
← Blog
Developer

Regular Expressions — A Practical Guide for Developers

Learn regular expressions from scratch. Syntax, common patterns, flags, and practical examples with our free regex tester.

I avoided regex for years. Every time I needed to validate an email or parse a log line, I'd write 20 lines of string manipulation code instead of learning the syntax. Then I got paired with a senior dev who wrote ^\b\w+@\w+\.\w+\b$ in about 3 seconds and moved on. That was the day I decided to actually learn regex.

What Is a Regular Expression?

A regular expression is a pattern that describes a set of strings. You use it to:

  • Search for specific text patterns
  • Validate input (emails, phone numbers, etc.)
  • Replace text programmatically
  • Extract data from unstructured text

Basic Syntax

Literal Characters

/hello/    matches "hello"
/123/      matches "123"

Special Characters

PatternMatchesExample
.Any character (except newline)h.t → "hat", "hot"
\dAny digit (0-9)\d{3} → "123"
\wWord character (a-z, A-Z, 0-9, _)\w+ → "hello_world"
\sWhitespace\s+ → " "
^Start of string^hello
$End of stringworld$
*0 or morea* → "", "a", "aaa"
+1 or morea+ → "a", "aaa"
?0 or 1colou?r → "color", "colour"
{n}Exactly n times\d{4} → "2025"
{n,m}Between n and m times\d{2,4} → "12", "1234"

Common Patterns

Email Validation

URL Matching

Phone Number (US)

IP Address

Regex Flags

FlagMeaningExample
gGlobal (all matches)/hello/g
iIgnore case/hello/i
mMultiline/^hello/m
sDot matches newline/./s
uUnicode support/\p{Emoji}/u

Groups and Capturing

Use parentheses to capture parts of a match:

/(\d{4})-(\d{2})-(\d{2})/
// Matches "2025-05-10", captures year, month, day

When NOT to Use Regex

  • Parsing HTML/XML — Use a proper parser instead
  • Complex nested structures — Regex can't handle recursion well
  • Very large files — Performance issues with massive text

Test Your Regex

Use our free regex tester to test patterns in real-time with highlighting, flags, and match details.

Try These Tools

More Articles