Skip to main content

Regex Tester

Test and debug regular expressions in real-time.

Pattern

//g

Test String

Matches

Enter a pattern and test string

Share:

Mastering Regular Expressions

Regular expressions (regex) are powerful tools for pattern matching and text manipulation. While they can look intimidating at first, understanding the basic building blocks allows you to solve complex text processing problems efficiently.

A black and white cartoon of a detective looking through a magnifying glass at a stream of floating letters and numbers, highlighting a specific pattern.A black and white cartoon of a detective looking through a magnifying glass at a stream of floating letters and numbers, highlighting a specific pattern.

Regex Building Blocks

A regular expression is composed of characters that represent patterns. Some characters match themselves, while others have special meanings.

Anchors

  • ^ : Matches the start of the string
  • $ : Matches the end of the string

Quantifiers

  • * : Matches 0 or more times
  • + : Matches 1 or more times
  • ? : Matches 0 or 1 time (optional)

Common Patterns

Email Validation

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

A standard pattern to validate email addresses, checking for username, @ symbol, domain, and extension.

Date Format (YYYY-MM-DD)

^\d{4}-\d{2}-\d{2}$

Matches a date string in ISO format, ensuring exactly 4 digits for year, 2 for month, and 2 for day.

A black and white cartoon of puzzle pieces fitting together to form a text string, symbolizing how regex components build a match.A black and white cartoon of puzzle pieces fitting together to form a text string, symbolizing how regex components build a match.

Deep Dive

Regular expressions have many more features like groups, lookaheads, and flags. For a comprehensive guide, check out the MDN Web Docs on Regular Expressions.