← All Guides
🛠️ Developer

Regular Expressions: A Practical Guide for Developers

8 min read · Updated June 2026

Regular expressions (regex) are a powerful pattern-matching language used in every programming language, text editor, and search tool. They can look intimidating, but once you understand the building blocks, you can read and write any regex.

The Building Blocks

Character Classes

PatternMatches
.Any character except newline
\dDigit [0-9]
\wWord character [a-zA-Z0-9_]
\sWhitespace (space, tab, newline)
[abc]Any of a, b, or c
[^abc]Anything except a, b, or c

Quantifiers

PatternMatchesType
*0 or moreGreedy
+1 or moreGreedy
?0 or 1Greedy
{n,m}Between n and mGreedy
*?0 or moreLazy
+?1 or moreLazy

Groups and References

  • (abc) — Capturing group (can be referenced as $1 or \1)
  • (?:abc) — Non-capturing group (doesn't create a reference)
  • (?<name>abc) — Named capturing group
  • abc|def — Alternation (matches abc OR def)

Flags

FlagNameEffect
gGlobalFind all matches, not just the first
iCase-insensitiveMatch regardless of case
mMultiline^ and $ match each line, not just the whole string
sDotall. matches newlines too
uUnicodeEnable Unicode property escapes (\p{L})
yStickyMatch only at lastIndex position

Common Patterns You'll Use

  • Email: /^[^\s@]+@[^\s@]+\.[^\s@]+$/
  • URL: /https?:\/\/(www\.)?[\w-]+\.[\w]{2,}(\/[\w-]*)*$/
  • Phone (US): /\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}/
  • IPv4: /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/
  • Date (YYYY-MM-DD): /\d{4}-\d{2}-\d{2}/

🧪 Test your Regex Live

Use our Regex Tester & Highlighter to test any pattern with real-time match highlighting, capture group display, and all flag support.

The Bottom Line

  1. Regex is built from character classes, quantifiers, groups, and anchors
  2. Use lazy quantifiers (*? +?) to avoid over-matching
  3. Named groups (?<name>) make complex regex readable
  4. Always test with edge cases — regex bugs are subtle
  5. For complex parsing (HTML, CSV), use a proper parser, not regex

Disclaimer: This guide is for informational purposes only. Regex implementations vary slightly between languages — always test in your target environment.

Joke of the Day
Jul 28

What do you call a shoe made from a banana peel?

100% Free, Forever

Keep Tools Free for Everyone

No paywalls, no signups, no data sold. Built by a solo developer who believes useful tools should be accessible to everyone.

Support me on Ko-fi— keep tools free

100% of proceeds go towards hosting & building more free tools.