ToolPal
Developer reviewing patterns of code on a laptop screen

A Beginner's Guide to Regular Expressions — Learn Regex in 10 Minutes

📷 ThisIsEngineering / Pexels

A Beginner's Guide to Regular Expressions — Learn Regex in 10 Minutes

Master the basics of regular expressions with practical examples. Learn pattern matching, character classes, quantifiers, and more.

DBy Daniel ParkMarch 12, 20262 min read

What Are Regular Expressions?

A regular expression (regex) is a pattern that matches combinations of characters in a string. It is an extraordinarily powerful tool for searching text, validating input, and extracting data.

Basic Patterns

Literal Characters

The simplest regex is a plain string: hello matches the text "hello" anywhere in a larger string.

Special Characters (Metacharacters)

CharacterMeaningExample
.Any single characterh.t matches "hat", "hot", "hit"
^Start of string^Hello matches "Hello World"
$End of stringworld$ matches "hello world"
\dOne digit\d{3} matches "123"
\wLetter, digit, or underscore\w+ matches "hello"
\sWhitespace character\s+ matches spaces and tabs

Quantifiers

QuantifierMeaning
*0 or more times
+1 or more times
?0 or 1 time
{n}Exactly n times
{n,m}Between n and m times

Practical Examples

Email Validation

[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}

US Phone Number

\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}

URL Pattern

https?://[\w.-]+\.[a-zA-Z]{2,}[/\w.-]*

Try It Yourself

Practice is the best teacher. Test your regular expressions with real-time match highlighting in the free Regex Tester.

Frequently Asked Questions

D

About the author

Daniel Park

Senior frontend engineer based in Seoul. Seven years of experience building web applications at Korean SaaS companies, with a focus on developer tooling, web performance, and privacy-first architecture. Open-source contributor to the JavaScript ecosystem and founder of ToolPal.

Learn more

Share this article

XLinkedIn

Related Posts