Tutorials

Regular Expressions: A Practical Developer Tutorial

Marcus Brennanยทยท10 min read

Regular Expressions for Developers

Regular expressions (regex) are powerful pattern-matching tools used in nearly every programming language.

Basic Syntax

  • . (dot) โ€” Any character
    • โ€” 0 or more repetitions
    • โ€” 1 or more repetitions
  • ? โ€” 0 or 1 repetitions
  • ^ โ€” Start of string
  • $ โ€” End of string
  • [] โ€” Character class
  • () โ€” Capturing group

Common Patterns

Email: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$ UUID v4: ^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$ IP Address: ^(\d{1,3}.){3}\d{1,3}$

Flags

  • g โ€” Global (find all matches)
  • i โ€” Case insensitive
  • m โ€” Multiline
  • s โ€” Dot matches newlines

Try Regex Tester

Use our free Regex Tester to test patterns with real-time match highlighting.

MB

Marcus Brennan writes for CodeUtilityKit, where the team builds free, privacy-first developer tools that run entirely in your browser. Every guide is written and reviewed by developers who use these tools daily.