🔍
Regular Expression
//gm
Matches: 0
Text: 147 chars
✏️ Test String
🎯 Match Preview
0 matches
Type a pattern and test string to see matches highlighted here.

Writing a Regex Without a Tester Is Guesswork

Regular expressions are notorious for a specific kind of failure: they pass every test case you thought of, then break in production on the one case you didn't. The email that contains a plus sign. The phone number with parentheses. The filename with two dots. You discover these failures only because real users send real data, which is far too late.

A regex tester inverts this. You collect real examples — good inputs, bad inputs, edge cases — paste them into the test string, and watch matches highlight as you refine the pattern. Every adjustment shows its effect immediately. You discover the failure modes during development, when fixing them is free, rather than after deployment when it costs support tickets.

Understanding What This Tester Shows You

The match panel isn't just a count of how many matches were found. For each match it shows the exact matched text, the character indices where the match starts and ends, and — if your pattern uses capture groups — the content of each captured group with its position. Named capture groups appear with their names, so you can verify that (?<year>\d4) is actually capturing what you think it's capturing before you write match.groups.year in your code.

The Flag System — What Each One Changes

The g flag is the most commonly forgotten one. Without it, JavaScript's regex engine stops after the first match — useful for existence checks, useless for extracting all occurrences. Add g whenever you need to find all matches in a string. The m flag changes ^ and $ to match the start and end of each line rather than the whole string — critical for line-by-line processing. The s flag makes . match newline characters, which it normally skips. The i flag handles case-insensitive matching without rewriting the pattern with character classes.

The u flag deserves special mention for internationalization work. Without it, a character like \w only matches ASCII word characters. With u enabled, Unicode property escapes like \p{Script=Latin} and \p{Decimal_Number} let you match by Unicode character properties rather than encoding ranges.

Practical Patterns for Common Validation Tasks

  • Email validation: /^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$/ — handles standard emails including plus-addressing and subdomain hosts.
  • URL detection: /https?:\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&amp;:/~\+#]*)/g — finds HTTP and HTTPS URLs in text.
  • ISO date matching: /\d4-\d2-\d2/g — finds YYYY-MM-DD formatted dates. Combine with the Epoch Converter to verify timestamps found by this pattern.
  • Extracting JSON field values: Finding specific values in JSON strings before parsing. Validate the pattern here, then use it in code — or use the JSON Formatter for the full structure.
  • URL routing patterns: Express, Next.js, and Flask use regex-style patterns for routing. Test route patterns against sample request paths to verify that both valid and invalid URLs match as expected.
  • Log parsing: Structure extraction from unstructured log lines. Use named capture groups to assign semantic names to captured fields.

Lookahead and Lookbehind — Assertions Without Consumption

Lookahead and lookbehind are zero-width assertions: they check what exists before or after the current position without consuming characters. Positive lookahead (?=...) asserts a pattern must follow; (?!...) asserts it must not. This is useful for matching numbers that are followed by specific units: \d+(?=px) matches the number before "px" without including "px" in the match.

Lookbehind works the same direction in reverse: (?<=\$)\d+ matches numbers preceded by a dollar sign without including the dollar sign in the match. JavaScript supports both positive and negative lookahead and lookbehind in modern engines.

When Regex Isn't the Right Tool

Regular expressions excel at pattern matching in strings but have well-known limitations. They cannot parse inherently recursive structures like HTML, XML, or JSON — the classic mistake that causes subtle parsing bugs. For those formats, use a proper parser: the HTML Encoder for HTML entities, the JSON Formatter for JSON, or the XML Formatter for XML. Regex is powerful on flat text; use it there and let dedicated parsers handle structure.

Verified by ToollyX Team · Last updated June 2026

Frequently Asked Questions

Disclaimer: This tester uses JavaScript's built-in RegExp engine. Patterns are evaluated entirely in your browser.