Task-first regex patterns with examples and caveats.

Text & Parsing

Use this page to grab a useful starting pattern and then refine it. The patterns here are intentionally practical rather than exhaustive.

Validation
^[^\s@]+@[^\s@]+\.[^\s@]+$

Example: Useful for lightweight client-side checks where you only need a reasonable shape test.

Gotcha: This is intentionally simple and does not fully validate all valid email addresses. Use application validation for strict rules.

^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$

Example: Matches values like `#fff` and `#1f8ced`.

Gotcha: This pattern allows only 3-digit and 6-digit hex colors, not 4-digit or 8-digit alpha forms.

Capturing
(\d+)

Example: Example input: Order #48291 ready. This pattern captures 48291 as group 1.

Gotcha: This captures the first or each digit run depending on the regex engine and how you iterate matches.

Matching
\bword\b

Example: Use this when `word` should match by itself but not inside `swordfish` or `password`.

Gotcha: Word-boundary behavior depends on the engine and character set rules, especially with Unicode text.

Replacement



Regular Expressions (RegEx) in 100 Seconds

Web Services are like teenage sex. Everyone is talking about doing it, and those who are actually doing it are doing it badly.

Michelle Bustamante

CodersTool Categories