Skip to main content
C
CodeUtil

Regex Tester

Test and debug regular expressions with live highlighting and match results.

Loading tool...

Why I Built This Regex Tester

I built this regex tester because I was tired of debugging patterns directly in my code. After one too many console.log sessions trying to figure out why my pattern wasn't matching, I decided to create a tool where I could test everything first. Now I use this daily before writing a single line of regex in production code.

Features I Use Every Day

  • Live Highlighting - Honestly, this is the killer feature. I can see matches instantly as I tweak the pattern.
  • Flag Support - Toggle global (g), case-insensitive (i), multiline (m), dotall (s), and unicode (u) flags with one click
  • Match Details - I can see exactly what each group captures, which saves me so much debugging time
  • Replace Mode - Test find-and-replace before running it on real data. I learned this lesson the hard way.
  • Common Patterns - Quick access to patterns I use constantly: email, URL, phone
  • Cheat Sheet - Because honestly, I can never remember the syntax for lookaheads

I often use this alongside the JSON Formatter when parsing log files and the URL Encoder when testing patterns against query strings.

Regex Flags Explained

  • g (Global) - Find all matches, not just the first one
  • i (Case Insensitive) - Match regardless of letter case
  • m (Multiline) - ^ and $ match start/end of each line
  • s (Dotall) - Dot (.) matches newline characters
  • u (Unicode) - Enable full Unicode support

Patterns I Keep Coming Back To

After years of regex debugging, these are the patterns I reach for most often. They work across JavaScript, Python, PHP, and basically any regex engine I've used.

Email Validation

The pattern ^[\w.-]+@[\w.-]+\.\w{2,}$ handles basic email validation. The thing is, email validation is surprisingly complex. In my experience, this pattern catches 95% of cases, but for production I usually reach for a proper validation library.

URL Matching

I use https?://[\w.-]+(?:/[\w./-]*)? to match HTTP and HTTPS URLs. It grabs the protocol, domain, and optional path. When I need query strings and fragments too, I extend it, but this basic version handles most of my use cases.

Phone Numbers

Phone numbers are a nightmare, honestly. I use \+?[\d\s-]{10,} as a flexible starting point. For anything serious, I reach for libphonenumber because international formats are wild.

Date Formats

Match ISO dates with \d{4}-\d{2}-\d{2} or common US format with \d{1,2}/\d{1,2}/\d{2,4}. One thing to remember: regex validates format, not whether the date makes sense. February 30th would still match, so I always combine this with date parsing.

Real Examples From My Work

Here are patterns I've actually used in production. You can paste these directly into the tester above to see how they work.

Email Validation Example

Test string: [email protected], invalid-email, [email protected]. The pattern ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ validates standard email formats. Pro tip: use the multiline flag (m) to validate multiple emails line by line.

URL Validation Example

Test string: https://example.com/path?query=1, ftp://invalid, http://localhost:3000. The pattern ^https?://[a-zA-Z0-9.-]+(?::\d+)?(?:/[^\s]*)?$ validates HTTP/HTTPS URLs with optional port numbers. I add (?:\?[^\s]*)? when I need query strings too.

Phone Number Validation Example

Test string: +1-555-123-4567, (555) 123-4567, 555.123.4567. Use ^\+?1?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$for North American formats. This handles parentheses, dashes, dots, and spaces. For international numbers, I always recommend libphonenumber alongside regex.

Related Articles

Frequently Asked Questions

Is my data secure?

Yep, everything runs in your browser. I built it this way because I use it with production data myself. Your patterns and test strings never leave your machine.

What regex flavor is supported?

This uses JavaScript's native RegExp engine (ECMAScript syntax). In my experience, it's compatible with most modern languages and tools, so patterns I test here usually work the same everywhere. For a full syntax reference, see MDN's Regular Expressions guide.

How do I use capture groups in replacement?

Use $1, $2, $3 to reference captured groups in your replacement string. For example, with pattern (\w+)@(\w+) and replacement $2:$1, the text "user@domain" becomes "domain:user". I use this all the time for reformatting data.