DevKits

Regex Tester & Debugger

Test regular expressions online. Live match highlighting, capture groups, and support for JavaScript flags (g, i, m, s, u, y).

Last updated:

//g
Contact us at hello@devkits.io or support@example.com for help.
Match 1 @ index 14
hello@devkits.io
Group 1: hello
Group 2: devkits.io
Match 2 @ index 34
support@example.com
Group 1: support
Group 2: example.com

Type a regex and test string above — matches, capture groups, and named groups are highlighted live as you edit.

What is Regex Tester?

A regular expression is a mini-language for describing text patterns. This tester uses the JavaScript (ECMAScript) regex flavor — the same rules that run in your browser and Node.js. Live match highlighting, group extraction, and flag toggles are all evaluated locally.

How to test a regular expression

  1. 1Type or paste your pattern into the Regex field (no need for surrounding slashes).
  2. 2Toggle flags: g (global), i (case-insensitive), m (multiline), s (dotAll), u (unicode), y (sticky).
  3. 3Paste the test text into the input area — matches highlight in real time.
  4. 4Expand the Matches panel to see each capture group, named group, and match position.

Use Cases

Validate user input

Emails, phone numbers, postal codes, slugs — anywhere you need a lightweight format check without pulling in a validation library.

Extract structured data from text

Pull IDs out of log lines, extract prices from HTML, or split a URL into parts using capture groups.

Search and replace in code

Modern editors accept regex for find-and-replace with `$1`, `$2` back-references. Test them here before committing.

Redirect and rewrite rules

nginx `location ~`, Vercel/Netlify redirects, and AWS CloudFront rules all use regex. Prototype and debug them here.

Code Examples

Regex in JavaScript

const re = /(\w+)@(\w+\.\w+)/g;
for (const match of "a@b.com c@d.io".matchAll(re)) {
  console.log(match[1], match[2]);
}

Regex in Python (re)

import re
for m in re.finditer(r"(\w+)@(\w+\.\w+)", text):
    print(m.group(1), m.group(2))

Regex in Go

import "regexp"

re := regexp.MustCompile(`(\w+)@(\w+\.\w+)`)
for _, m := range re.FindAllStringSubmatch(text, -1) {
    fmt.Println(m[1], m[2])
}

Regex from grep

# -E enables extended regex (no backslash for group parens)
echo "$logs" | grep -E "([0-9]{3}) ms"

Key Concepts

Character class
`[abc]` matches any one of a, b, c. `[a-z]` a range. `[^abc]` negation. `\d` `\w` `\s` are shorthand for digit / word / whitespace.
Quantifier
`*` 0 or more, `+` 1 or more, `?` 0 or 1, `{n}` exactly n, `{n,m}` between n and m. Add `?` after any quantifier to make it lazy (non-greedy).
Anchor
`^` start of string (or line, with `m` flag). `$` end of string (or line). `\b` word boundary.
Capture group
`(...)` captures, `(?:...)` groups without capturing, `(?<name>...)` named capture. Back-reference with `\1` or `\k<name>`.
Lookaround
`(?=...)` positive lookahead, `(?!...)` negative, `(?<=...)` positive lookbehind, `(?<!...)` negative. Zero-width — they don't consume input.

Tips & Best Practices

  • Prefer non-greedy `.*?` over `.*` when parsing HTML-ish or delimited content — greedy matches are the #1 source of regex bugs.
  • For very complex patterns, split into multiple simpler regexes chained by code. Easier to read, test, and maintain.
  • Never use regex to parse HTML or JSON in production. Use a real parser. Regex is fine for quick extraction on trusted input.
  • Watch out for catastrophic backtracking — patterns like `(a+)+$` can hang on adversarial input. Use tools like safe-regex to audit.

Frequently Asked Questions

Which regex flavor does this tool use?

JavaScript (ECMAScript) regex, exactly as it behaves in modern browsers. Features specific to PCRE or Python are not supported.

What do the flags g, i, m, s, u, y mean?

g = global (find all matches), i = case-insensitive, m = multiline (^/$ match line boundaries), s = dotAll (. matches newlines), u = unicode, y = sticky (match starts at lastIndex).

Related Tools