ToolBox Hub

Regular Expressions Guide for Beginners - Learn Regex in 10 Minutes

Regular Expressions Guide for Beginners - Learn Regex in 10 Minutes

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

March 12, 20262 min read

What Are Regular Expressions?

Regular expressions (regex) are patterns used to match character combinations in strings. They're incredibly powerful for text search, validation, and manipulation.

Basic Patterns

Literal Characters

The simplest regex is just a plain string: hello matches "hello" in any text.

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"
\dAny digit\d{3} matches "123"
\wWord character (a-z, A-Z, 0-9, _)\w+ matches "hello"
\sWhitespace\s+ matches spaces, tabs

Quantifiers

QuantifierMeaning
*Zero or more
+One or more
?Zero or one
{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,}

Phone Number

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

URL Pattern

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

IP Address

\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}

Character Classes

  • [abc] - Matches a, b, or c
  • [a-z] - Matches any lowercase letter
  • [^abc] - Matches anything except a, b, or c
  • [0-9] - Same as \d

Groups and Alternation

  • (abc) - Capturing group
  • (?:abc) - Non-capturing group
  • a|b - Matches a or b

Test Your Regex

Practice makes perfect! Use our free Regex Tester to test your regular expressions in real-time with instant match highlighting.

Related Posts