Dev Hub Solutions

Product studio

Get in touch
DeveloperLive

Regex Tester

Build, test and debug regular expressions.

//
Contact: alice@example.com, bob@example.org Phone: +1 (415) 555-2671 URL: https://devhubsolutions.net/tools

Matches (2)

  • alice@example.com

    index: 9

  • bob@example.org

    index: 28

About Regex Tester

A friendly regex playground with live match highlighting and a cheatsheet.

How to use

  1. 1Type a regex pattern.
  2. 2Paste the text you want to match against.
  3. 3Toggle flags (g, i, m, s, u) and view captures.

Regular expressions are the most underused and most misused tool in a developer's belt. The syntax is dense, the failure modes are subtle, and the gap between "works on this example" and "works on every input" is wider than it looks. This tester is a place to close that gap — type a pattern, paste real input, watch every match light up live, and tune until the captures match what you actually want.

JavaScript flavour, and why that matters

Regex syntax is a family of dialects. JavaScript regex is what runs here — it's also what runs in Node, Bun, Deno, every modern browser, and most JavaScript-shaped runtimes. Python's `re`, Go's `regexp`, Ruby's Oniguruma, and the broader PCRE family share most of the basics but diverge on the edges: lookbehinds, named groups, atomic groups, Unicode property escapes, possessive quantifiers, recursion. If you're authoring a pattern that has to run in another language, prototype here, then double-check the target engine's docs.

Anchors, quantifiers, character classes — the working vocabulary

`^` anchors to the start of the string (or each line with the `m` flag), `$` to the end. `\d` is a digit, `\w` is a word character (letters, digits, underscore — note: includes underscore), `\s` is whitespace. `*` is zero or more, `+` is one or more, `?` is zero or one. Append `?` to any quantifier to make it lazy — `.*?` instead of `.*`. Groups are `(...)` for capturing, `(?:...)` for non-capturing (slightly faster, doesn't pollute your captures), and `(?<name>...)` for named groups. Square brackets define a character class: `[a-zA-Z0-9_]` is the explicit form of `\w`.

Common patterns worth memorising

An email address (good enough): `^[^\s@]+@[^\s@]+\.[^\s@]+$`. A URL: `^https?:\/\/[^\s]+$`. An IPv4 address: `^(?:\d{1,3}\.){3}\d{1,3}$` — note this doesn't validate that each octet is 0-255; full validation is uglier. A US phone number: `^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$`. A UUID v4: `^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$`. A semantic version: `^\d+\.\d+\.\d+(?:-[\w.]+)?(?:\+[\w.]+)?$`. Each of these has a dedicated page on this site with explanation and edge cases.

When not to use regex

Parsing HTML. Parsing JSON. Parsing nested structures of any kind. Regex describes regular languages — flat, unbalanced patterns. The moment your input has balanced delimiters that nest arbitrarily, a regex either becomes monstrous or fails on cases you didn't think of. Use a real parser: `DOMParser` for HTML, `JSON.parse` for JSON, a peg.js / nearley / chevrotain grammar for anything else. Regex is for extracting flat fields from text, validating shape, and search-and-replace — that's where it earns its keep.

Frequently asked questions

Quick answers to the questions people actually ask about Regex Tester.

Which regex flavour does this support?

JavaScript regex (ECMAScript), which is also what Node.js, Deno, Bun, and most modern web tooling use. If you're writing regex for Python (`re` module), Go (`regexp`), Ruby (Oniguruma), or PCRE, behaviour will differ — especially around lookbehinds, named groups, and Unicode property escapes. Match your tooling.

What does each flag do?

`g` (global) finds every match, not just the first. `i` (case-insensitive) ignores letter case. `m` (multiline) makes `^` and `$` match line starts and ends, not just string start and end. `s` (dotAll) lets `.` match newlines. `u` (unicode) enables Unicode property escapes like `\p{Letter}` and treats surrogate pairs correctly. `y` (sticky) anchors the search to `lastIndex` — rarely needed outside of streaming parsers.

How do I match an email address?

The honest answer: you don't, perfectly. The full RFC 5322 grammar is hundreds of lines. For 99% of cases, `/^[^\s@]+@[^\s@]+\.[^\s@]+$/` is good enough — at least one character before the `@`, at least one between `@` and the last `.`, and at least one after. If you need real correctness, validate with a library or by sending a confirmation email.

Why does `.*` match everything except newlines?

Because `.` excludes newlines by default in JavaScript regex. Add the `s` flag (dotAll) to make `.` match newlines too. Or use `[\s\S]*` as an explicit "match anything including newlines" idiom — it's universally portable across regex engines.

What's the difference between greedy and lazy quantifiers?

`*`, `+`, and `?` are greedy — they match as much as possible, then back off. Append `?` to make them lazy — they match as little as possible, then extend. The classic trap: `<.*>` matches `<a>foo</a>` in full because greedy. `<.*?>` matches just `<a>`. Lazy is usually what you want when extracting tags or quoted strings.

Why is my regex matching too much?

Usually one of three reasons: a greedy quantifier where you wanted lazy (see above), missing anchors (`^` and `$`), or a character class that's broader than intended (e.g. `\w` matches letters, digits, and underscore — not just letters). Test with edge cases and read each character of your pattern out loud.