3tej home
← All Games

What is Regex Tester?

A regex tester runs a regular expression against your text and shows what it matches. Type a pattern and flags, paste a test string, and matches highlight in yellow with a live count, all in your browser using the JavaScript RegExp engine. Nothing is uploaded.

Regex Tester

Test regex patterns. Highlight matches.

//

How to use

  1. Type a regex pattern in the field between the two slashes, and any flags (such as g, i, or m) in the small box on the right.
  2. Type or paste test text in the area below. Every match is highlighted in yellow as you type.
  3. Read the match count shown above the result. An invalid pattern shows the error message instead, so you can fix syntax on the spot.

About this tool

This regex tester evaluates your pattern against test text in real time, using the browser's native JavaScript RegExp engine (ECMAScript). Every match is highlighted in yellow and the running total appears above the result. Because it runs entirely client-side, your patterns and test data never leave the page, which makes it safe to paste logs, sample records, or anything sensitive while you iterate.

Regular expressions are a compact language for describing text patterns. The same core syntax, with minor dialect differences, powers find-and-replace in editors, validation rules in web forms, log filtering in tools like grep, and tokenizers in compilers. Learning the handful of metacharacters below covers the large majority of everyday matching tasks, and a live tester is the fastest way to build the muscle memory: change one symbol, watch the highlights move, and you understand the rule immediately.

The default pattern, \b\w+\b with the g flag, matches every whole word in the sample. The \b markers are word boundaries (zero-width positions between a word and a non-word character), \w means a word character (letters, digits, or underscore), and + means one or more of them. Try deleting a \b or swapping + for * to see exactly how each piece changes the result.

Regex 101: the essentials

A regular expression is a search pattern - a tiny language for matching text. The same syntax works (with small dialect differences) in JavaScript, Python, Java, Go, Rust, grep, sed, and PCRE.

Common syntax

PatternMatchesExample
.Any single character (except newline by default)a.c matches abc, aXc, a c
\d \w \sDigit / word-char / whitespace\d\d matches any 2 digits
[abc]Any of a, b, or c[aeiou] matches any vowel
[^abc]Anything except a, b, c[^0-9] matches a non-digit
*0 or more of previousa*b matches b, ab, aab
+1 or morea+b matches ab, aab (not b)
?0 or 1 (optional)colou?r matches color and colour
{n,m}Between n and m repetitions\d{4,8} matches 4-8 digits
^ $Start / end of line^abc$ matches a line that is exactly abc
(abc)Capture group(\d{3})-\1 matches 123-123 (back-reference)
a|bEither a or bcat|dog matches cat or dog
\bWord boundary\bword\b matches whole word only

Greedy vs lazy

By default *, +, and ? are greedy - they match as much as possible. Add ? after to make them lazy:

  • Greedy: <.*> on <b>hi</b> matches the whole thing <b>hi</b>.
  • Lazy: <.*?> on the same input matches just <b>.

Worked example: extracting a date

Say you want to pull dates in YYYY-MM-DD form out of a block of text. Build the pattern piece by piece. A four-digit year is \d{4}, a literal hyphen is just -, and a two-digit month or day is \d{2}. Joined together that is \d{4}-\d{2}-\d{2}. Add the global flag g so it finds every date, not just the first, and paste a sentence like Invoices dated 2026-05-28 and 2026-06-15 are due. into the test box. The tester highlights both dates and reports 2 matches. To require the date to sit on its own line, wrap it with anchors as ^\d{4}-\d{2}-\d{2}$ and turn on the m flag so the anchors apply per line. This incremental approach, test after each addition, is far more reliable than writing a long pattern blind.

Capture groups and backreferences

Parentheses do two jobs at once. They group sub-patterns so a quantifier applies to the whole group, and they capture the matched text for reuse. In (\d{4})-(\d{2})-(\d{2}) the year, month, and day are captured as groups 1, 2, and 3, which a replace operation can reference as $1, $2, $3 (or \1 in some engines). Named groups make this readable: (?<year>\d{4}) lets you refer to year instead of a number. A backreference such as \1 inside the pattern itself matches the same text the group already captured, so (\w+) \1 finds doubled words like the the. If you only want grouping without the capture overhead, use a non-capturing group (?:...).

Flags / modifiers

FlagJavaScriptEffect
g/abc/gMatch all occurrences (not just first)
i/abc/iCase-insensitive
m/abc/m^ and $ match start/end of each line, not entire string
s/abc/s. matches newlines too (single line / dotall)
u/abc/uUnicode-aware (proper handling of emojis, accented chars)
y/abc/ySticky - only match at lastIndex (used by lexers)

10 most-needed regex patterns

What you wantRegex
Email (basic)^[\w.+-]+@[\w.-]+\.\w{2,}$
URLhttps?://[\w.-]+(?:/[\w./?&=-]*)?
IPv4 address\b(?:\d{1,3}\.){3}\d{1,3}\b
US phone^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$
Indian PAN^[A-Z]{5}\d{4}[A-Z]$
UK postcode^[A-Z]{1,2}\d[A-Z\d]?\s*\d[A-Z]{2}$
YYYY-MM-DD^\d{4}-\d{2}-\d{2}$
Hex color^#(?:[0-9A-Fa-f]{3}){1,2}$
Strong password (8+, upper, lower, digit)^(?=.*[A-Z])(?=.*[a-z])(?=.*\d).{8,}$
HTML tag (lazy)<([a-z]+)[^>]*>.*?</\1>

Common mistakes

  • Forgetting to escape - . matches any character; for a literal dot, use \.. Same for + * ? ( ) [ ] { } | \ ^ $.
  • Catastrophic backtracking - patterns like (a+)+b can take seconds on inputs that look harmless. Avoid nested repetition.
  • Trying to parse HTML - HTML is recursive, regex is not. Use a real HTML parser (DOMParser, BeautifulSoup, cheerio).
  • Greedy by default - ".*" on "a" "b" matches the whole line. Use ".*?" when you want the smallest match.

Frequently asked questions

Why is my regex so slow?

Most likely catastrophic backtracking. Replace nested quantifiers - patterns like (a+)+ become a+. Possessive quantifiers (a++) prevent backtracking entirely but are not supported in JavaScript.

What flavor of regex does this tool use?

JavaScript regex (ECMAScript 2018+). It supports unicode property escapes (\p{L}), named groups ((?...)), and lookbehinds ((?<=foo)bar).

Can I use regex to validate email?

Only superficially. There's no regex that correctly validates RFC 5322 - the spec is too complex. Use a basic pattern (^[^@]+@[^@]+\.[^@]+$) and verify by sending a confirmation email.

How do I match a literal slash?

In JavaScript regex literals, escape the / as \/. As a string passed to new RegExp(), use plain /. The slash is only special in literals because that's the delimiter.

What is the difference between . and \s?

The dot matches any character except newlines unless the s flag is set. The \s class matches only whitespace: space, tab, newline, carriage return, form feed, and vertical tab. So the dot is broad (almost everything) while \s is narrow (only blank characters).

Why does my pattern match nothing or match too much?

Two usual causes. Matching nothing often means an unescaped special character, such as a literal dot written as . instead of \. Matching too much is almost always greedy quantifiers: .* grabs everything up to the last possible point. Switch to a lazy .*? or a negated character class like [^"]* to stop at the first boundary.

CT
3Tej Editorial
Free, browser-based developer and text tools.