FTJ
← Blog
Developer

Regex Cheat Sheet: Common Patterns for Everyday Use

Regex keeps slipping your mind? This guide breaks down the patterns you'll actually use — email, phone, URLs — with a free tester.

# Regex Cheat Sheet: Patterns You'll Actually Use

I avoided regex for years. Every time I needed to validate an email or parse a log line, I'd write 20 lines of string manipulation code instead of learning the syntax. Then I got paired with a senior dev who wrote ^[\w.-]+@[\w.-]+\.\w+$ in about 5 seconds and I felt stupid.

Here's what I wish someone had told me: you don't need to memorize regex. You just need a cheat sheet of patterns you'll actually use, and a tester to experiment with.

The Patterns I Use Weekly

Email validation: ` ^[\w.+-]+@[\w-]+\.[\w.-]+$ `

URL extraction: ` https?://[\w.-]+(?:/[\w./?&=-]*)? `

Phone number (US): ` ^\+?1?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$ `

Match all text between quotes: ` "([^"]*)" `

IP address: ` ^(?:\d{1,3}\.){3}\d{1,3}$ `

Date (YYYY-MM-DD): ` ^\d{4}-\d{2}-\d{2}$ `

The 10 Symbols That Cover 90% of Use Cases

SymbolMeaning
.Any character
*Zero or more
+One or more
?Optional (zero or one)
\dDigit (0-9)
\wWord character (letter, digit, underscore)
\sWhitespace
[]Character set
()Capture group
^ / $Start / end of string

Flags Worth Knowing

  • g — Global (match all, not just first)
  • i — Case-insensitive
  • m — Multiline (^ and $ match line boundaries)

Testing Regex

Don't guess. Use our Regex Tester to paste your pattern and test text, see matches highlighted in real time. Free, no signup.

## Regex Cheat Sheet

Common patterns you will use repeatedly:

  • \d+ — One or more digits
  • \w+ — One or more word characters (letters, digits, underscore)
  • \s+ — One or more whitespace characters
  • [a-z]+ — One or more lowercase letters
  • [^a-z] — Any character that is not a lowercase letter
  • ^pattern — Match at the start of the string
  • pattern$ — Match at the end of the string
  • (\d{4})-(\d{2})-(\d{2}) — Capture groups for a date
  • (?:abc) — Non-capturing group
  • a|b — Match a OR b

Regex in Different Languages

Syntax is mostly consistent, but there are differences:

  • JavaScript: /pattern/flags or new RegExp("pattern", "flags"). Flags: g (global), i (case-insensitive), m (multiline), s (dotall).
  • Python: re.match(), re.search(), re.findall(), re.sub(). Use raw strings: r"d+".
  • Go: regexp.Compile(), regexp.MustCompile(). Go uses RE2, which does not support backreferences.
  • Java: Pattern.compile(), Matcher class. Verbose syntax but full feature support.
  • grep: grep -E for extended regex, grep -P for PCRE (Perl-compatible).

Performance Tips

  1. Avoid catastrophic backtracking: Patterns like (a+)+b can cause exponential matching time on strings of a characters. Use atomic groups or possessive quantifiers when available.
  2. Anchor your patterns: ^\d{4}$ is faster than \d{4} because the anchors allow the engine to fail early.
  3. Be specific: [0-9] is faster than \d in some engines because \d may match Unicode digits.
  4. Precompile: If you use a pattern in a loop, compile it once and reuse the compiled object.

Try These Tools

More Articles