DEV Community

Muhammad Awais
Muhammad Awais

Posted on • Originally published at webtoolshub.online

Stop Testing Regex in Your Browser Console Use This Free Tool Instead

Every developer has done this at least once.

You need a regex pattern. You open the browser console, type something like:

/^[\w.-]+@[\w.-]+\.\w{2,}$/.test("user@example.com")
Enter fullscreen mode Exit fullscreen mode

It returns true. Great. But does it handle edge cases? What about user+tag@sub.domain.co.uk? What about an empty string? What about unicode characters in the local part?

So you modify the pattern. Test again. Modify. Test. Realize you don't actually understand why the {2,} is there. Open a Stack Overflow tab. Lose 40 minutes.

There's a better way.


What I Actually Use Now

I built a free browser-based regex tester at WebToolsHub that handles the parts the browser console can't.

Here's what it does differently:

Live match highlighting as you type your pattern, every match in the test string gets highlighted in real time. You see immediately if you're matching too much or too little, without running console.log a dozen times.

Flag toggles g, i, m, s, u flags are buttons, not things you have to remember to append to your regex literal. Toggle them and watch the matches change.

Match breakdown you see not just whether something matched, but what each capture group captured. Essential when your pattern has 4 nested groups and you're not sure which one is eating your data.

No data sent anywhere this one matters more than it sounds. I work on projects where the test strings contain internal data user IDs, API formats, log patterns from production systems. Running those through an online tool that sends data to a server is a security concern. This tool runs entirely in your browser. Open DevTools, watch the Network tab while you test nothing goes out.


Quick Example Email Validation

Let's say you're validating email addresses. A naive pattern:

/^\S+@\S+\.\S+$/
Enter fullscreen mode Exit fullscreen mode

Paste that into the pattern field and test against these:

user@example.com          ← should match ✅
user+tag@example.com      ← should match ✅  
user@sub.domain.co.uk     ← should match ✅
@example.com              ← should NOT match ❌
user@.com                 ← should NOT match ❌
plainaddress              ← should NOT match ❌
Enter fullscreen mode Exit fullscreen mode

Your naive pattern will match @example.com - \S allows @ as the first character. The live highlighting shows you this instantly.

A tighter version:

/^[^\s@]+@[^\s@]+\.[^\s@]+$/
Enter fullscreen mode Exit fullscreen mode

Still not RFC 5322 compliant, but it handles the obvious edge cases. The tool shows you exactly which test strings it matches and which ones slip through.


Flags That Actually Matter

Most developers use g (global) and i (case-insensitive) and that's it. But m and s change behavior in ways that trip people up.

m flag multiline mode

Without m, ^ matches the start of the entire string and $ matches the end.
With m, ^ matches the start of each line and $ matches the end of each line.

This matters when you're parsing multi-line logs or configuration files. Toggle the m flag in the tool and watch what ^\d+ does to a string with line breaks it's immediately obvious.

s flag dotAll mode

By default, . doesn't match newlines. The s flag makes it match everything including \n.

If you've ever written [\s\S]* instead of .* to match across newlines that's the problem s solves. Most developers don't know this flag exists because it was added in ES2018 and isn't in older tutorials.


The Patterns I Keep Coming Back To

A few patterns I find myself reusing across projects:

Slug validation (URL path segments):

/^[a-z0-9]+(?:-[a-z0-9]+)*$/
Enter fullscreen mode Exit fullscreen mode

ISO 8601 date (basic):

/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/
Enter fullscreen mode Exit fullscreen mode

Semantic version:

/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([\da-z-]+(?:\.[\da-z-]+)*))?(?:\+([\da-z-]+(?:\.[\da-z-]+)*))?$/i
Enter fullscreen mode Exit fullscreen mode

JWT format check (not verification - just format):

/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
Enter fullscreen mode Exit fullscreen mode

Paste any of these into the tester and run them against your actual test cases. Seeing the match groups broken out makes it much easier to understand why a pattern works or why it doesn't.


One Thing Worth Knowing About Regex Performance

Complex patterns with lots of backtracking can be slow in some cases, catastrophically slow. The classic example is something like (a+)+ tested against a string like aaaaaab. This is called catastrophic backtracking or ReDoS (Regular Expression Denial of Service).

If you're putting regex patterns into user-facing code form validation, URL routing, text processing it's worth understanding the risk. The MDN documentation on regex performance covers this, and the tool makes it easy to test patterns against adversarial inputs before they go anywhere near production.


Try It

Regex Tester & Debugger - WebToolsHub

Free, no account, runs in your browser. If you want the deeper explanation of how JavaScript regex works under the hood flags, lookaheads, named capture groups, Unicode property escapes there's a full guide at WebToolsHub Blog too.

What patterns do you find yourself reusing most? Drop them in the comments always looking for good ones to add to my snippets collection.

Top comments (0)