Regex Tester (JavaScript)

What is regex?

Regex — short for regular expression, also written regexp — is a compact pattern language for matching, searching, and extracting text. Instead of searching for one exact string, a regex describes a shape (say, "three digits, then a dash, then four digits") that can match many different inputs at once. The core syntax — character classes, quantifiers, groups — is broadly shared across languages: JavaScript, Python, Java, grep, and most others all build on the same ideas, with some differences in the details (see the FAQ below).

Common regex flags

Regex cheat sheet

PatternMatches
.Any character except newline
\d / \DA digit / anything that isn't a digit
\w / \WA word character (letter, digit, underscore) / anything that isn't
\s / \SWhitespace / anything that isn't whitespace
\bA word boundary
^ / $Start / end of the string (or line, with the m flag)
* / + / ?Zero or more / one or more / zero or one of the previous token
{n} / {n,} / {n,m}Exactly n / n or more / between n and m repetitions
[abc] / [^abc]Any one of a, b, c / any character except a, b, c
[a-z]Any character in the range a to z
(...)Capture group — remembers what it matched
(?:...)Non-capturing group — groups without remembering
(?<name>...)Named capture group
|Alternation — matches whatever is on either side
(?=...) / (?!...)Positive / negative lookahead
(?<=...) / (?<!...)Positive / negative lookbehind

Common pattern examples

What you want to matchPattern
An email address (simple)[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}
A number, with optional decimals-?\d+(\.\d+)?
A dollar amount like $1,234.56\$[\d,]+(\.\d{2})?
A US phone number\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}
A URL (simple)https?://[^\s]+
A hex color code#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})

These are deliberately simplified — a fully spec-compliant email or URL pattern is much longer and rarely worth it in practice. Paste any of these into the pattern field above and try them against real text.

Frequently asked questions

Does this tool send my pattern or text to a server?

No — matching runs entirely in your browser using JavaScript's built-in RegExp engine. Nothing is sent anywhere.

Why do some patterns run slowly or freeze the page?

Certain patterns — especially ones with nested quantifiers like (a+)+ — can exhibit "catastrophic backtracking" against specific input, where matching time grows exponentially with input length. Since this runs in your own browser tab, a slow pattern only affects your session; try a shorter test string or a less ambiguous pattern if it hangs.

Does this test Python, Java, or grep regex?

No — this tool uses JavaScript's native RegExp engine (ECMAScript syntax), since it runs entirely in your browser. Python (re), Java (java.util.regex), and grep (POSIX/PCRE) each use their own regex engine. The core syntax is largely shared — character classes, quantifiers, groups — but there are real differences: Python supports inline flags like (?i) that JavaScript doesn't, lookbehind support varies by engine and version, and escaping rules differ slightly. A pattern that works here will usually need small adjustments to run somewhere else.

Is this the same as a regex generator or regex builder?

Not quite. A regex generator tries to write a pattern for you from an example or a plain-English description; a regex builder is often a visual, click-together interface for constructing one. This tool assumes you already have a pattern — or are iterating on one — and lets you test it live against real text: a regex tester, not a regex writer.