Skip to main content
WorkUtilities
← All GuidesDeveloper Tools

How to Test Regular Expressions Online β€” Regex Cheat Sheet

Alex Morgan Β· 6 min read Β· Last updated June 2026


Writing a regular expression that works on your first test string but silently fails on edge cases is one of the most common (and hardest to spot) bugs in form validation, data parsing, and search/replace logic β€” testing against multiple real examples before shipping a regex catches this early. See our Complete Developer Tools Guide.


Why Test Before Deploying a Regex

Regex is unforgiving β€” a pattern that looks correct can still fail on unicode characters, optional/missing groups, or multiline input unless explicitly tested against varied real-world examples.


Quick-Reference Cheat Sheet

  • ^ β€” start of string
  • $ β€” end of string
  • . β€” any character
  • * β€” zero or more
  • + β€” one or more
  • ? β€” optional (zero or one)
  • \d β€” digit
  • \w β€” word character
  • \s β€” whitespace
  • [] β€” character set
  • () β€” capture group
  • {n,m} β€” repetition range
  • | β€” OR

Common Patterns Developers Search For

Email (practical): ^[\w.-]+@[\w.-]+\.\w+{2,}$ β€” covers most real emails; verify with a confirmation email, not regex alone.

URL: ^https?:\/\/[\w.-]+(?:\/[\w./?%&=-]*)?$

Phone: patterns vary heavily by country β€” a "universal" phone regex is notoriously unreliable. Test against your target region's formats.

Password strength: ^(?=.*[A-Za-z])(?=.*\d).{8,}$ β€” at least 8 chars, one letter, one digit.


Global vs Case-Insensitive Flags

The g flag matches all occurrences, not just the first. The i flag enables case-insensitive matching. Flag confusion is a frequent source of regex bugs β€” test both in the Regex Tester.


Frequently Asked Questions

Why does my regex match the first occurrence but not all of them?

You likely need the global flag (g), which tells the regex engine to find all matches in the string instead of stopping after the first one.

Is there one regex pattern that validates all email addresses correctly?

Not perfectly β€” fully RFC-compliant email validation is extremely complex. Most practical applications use a simpler pattern that covers 99% of real-world emails, combined with an actual verification email as the real validation step.

What's the difference between * and + in regex?

* matches zero or more occurrences of the preceding character (so it also matches none at all), while + requires at least one occurrence.

Why is my regex slow on long strings?

Certain patterns (especially nested quantifiers like "(a+)+") can cause "catastrophic backtracking," where the regex engine's processing time grows exponentially with input length. Testing against realistic-length input before deploying helps catch this.


Related Reading


Test Your Regex Pattern Now β†’

Ready to try it yourself?

Regex Tester β€” Free & Private

No signup. No upload to server. Runs in your browser.

Try Regex Tester β†’