Back to Tools

Regex Tester — Test JavaScript Regular Expressions Online, Capture Groups, Replace & Flags Real-Time Free

Test regex in real time. See all matches, capture groups, and match indexes highlighted. Test replace with $1 $2. JavaScript RegExp, all flags (g i m s u y). Free, 100% browser-based.

//

Flags: g

9 matches
Unique: 9Avg length: 3.9Coverage: 79.5%

Highlighted in test string

The quick brown fox jumps over the lazy dog.
#IndexMatchGroups
10The
24quick
310brown
416fox
520jumps
626over
731the
835lazy
940dog

Replace

Use $1, $2, … for capture groups; $& for full match.

What Is a Regular Expression?

A regular expression (regex) is a sequence of characters that defines a search pattern. It's used to find, match, validate, and replace text in strings. Regex is supported in virtually every programming language — JavaScript, Python, Java, Go, PHP, Ruby — making it one of the most universally useful developer skills. This tester uses the JavaScript RegExp engine (ECMAScript) and runs entirely in your browser; nothing is sent to any server.

Regex Quick Reference

Character classes

  • . — any character except newline
  • \d — digit [0-9]
  • \D — non-digit
  • \w — word character [a-zA-Z0-9_]
  • \W — non-word character
  • \s — whitespace
  • \S — non-whitespace

Quantifiers

  • * — 0 or more
  • + — 1 or more
  • ? — 0 or 1
  • {n} — exactly n
  • {n,} — n or more
  • {n,m} — between n and m

Anchors & groups

  • ^ — start of string/line
  • $ — end of string/line
  • \b — word boundary
  • (abc) — capture group
  • (?:abc) — non-capturing
  • (?<name>abc) — named group
  • (?=abc) — positive lookahead
  • (?!abc) — negative lookahead

JavaScript flags

  • g — global (find all matches)
  • i — case insensitive
  • m — multiline (^ $ per line)
  • s — dotAll (. matches newline)
  • u — unicode
  • y — sticky

Common Regex Patterns

Try these in the tester above — use the Sample patterns dropdown to load them.

  • Email: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
  • URL: https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}
  • Phone (US): ^\+?1?\s?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$
  • Date (YYYY-MM-DD): ^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$
  • IPv4: ^(\d{1,3}\.){3}\d{1,3}$
  • Password (min 8 chars, upper, lower, number): ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$

Frequently Asked Questions

How do I test a regex pattern online?
Paste your regular expression in the pattern field and your test string below it. Matches highlight instantly in real time. The results table shows every match, its position index, and any capture groups. No clicking required — results update as you type.
What is the g flag in JavaScript regex?
The g (global) flag makes the regex find ALL matches in the string instead of stopping after the first one. Without g, only the first match is returned. Most use cases require the g flag when searching or replacing in strings.
How do I use capture groups in regex replace?
Wrap the part you want to capture in parentheses in your pattern. In the replacement field, reference it with $1 (first group), $2 (second group), and so on. For example: pattern (\w+)\s(\w+) with replacement $2 $1 swaps the first two words.
What is the difference between + and * in regex?
* matches 0 or more occurrences — it can match nothing. + matches 1 or more — it requires at least one match. Use + when the character must appear at least once. Use * when it's optional.
What does \d mean in regex?
\d matches any digit character — equivalent to the character class [0-9]. Use \d+ to match one or more digits, \d4 to match exactly 4 digits. Use \D (uppercase) for the opposite — any non-digit character.

Related Tools

Pair regex with these developer tools:

What Is a Regex Tester?

A regex tester lets you write and validate regular expressions against sample text in real time, seeing exactly which characters match, which capture groups fire, and what a replacement produces — without writing a test script. This tester uses the JavaScript RegExp engine (ECMAScript), the same engine running in Node.js, browsers, and Deno.

Regular expressions are sequences of characters that define a search pattern. A pattern like \d{3}-\d{4} matches a 7-digit phone number; ^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$ validates email addresses. Testing live before using in production prevents subtle bugs from slipping through.

How it works

Test Regex Patterns in Real Time

01

Enter your pattern

Type a regex pattern (without the surrounding /slashes/). Toggle flags — g (global), i (case-insensitive), m (multiline), s (dotAll), u (Unicode), y (sticky).

02

Paste test string

Paste the text you want to match against. Matches highlight inline as you type — no need to click.

03

Inspect matches

The results table shows every match, its start index, length, and all capture group values ($1, $2…) extracted from the text.

04

Test replace

Switch to Replace mode and enter a replacement string with $1 $2 group references. See the transformed output immediately.

Use cases

When Developers Use a Regex Tester

Validate Input Formats

Test email, phone, ZIP code, and URL validation patterns before adding them to form validation or API schemas.

🔍

Grep Log Files

Build patterns to search log files for error codes, stack traces, IP addresses, or timestamp ranges.

✂️

Extract Data

Use capture groups to pull structured values (dates, IDs, tokens) out of unstructured text or API responses.

🔄

String Replacement

Test find-and-replace patterns for code refactoring, renaming variables, or transforming data formats.

🔗

URL Routing

Validate Next.js, Express, or Nginx route patterns against sample URLs to check path segments and query params.

🛡️

Security Filters

Test input sanitization patterns that block XSS payloads, SQL injection strings, or path traversal attempts.

JavaScript Regex Quick Reference

TokenMeaningExample
.Any character except newline (use s flag for newline)/h.t/ → "hat", "hit", "hot"
\dAny digit [0-9]/\d+/ → "42" in "page 42"
\wWord character [a-zA-Z0-9_]/\w+/ → "hello_world"
\sWhitespace (space, tab, newline)/a\sb/ → "a b"
^Start of string (or line with m flag)/^hello/ → only at start
$End of string (or line with m flag)/world$/ → only at end
*0 or more of the preceding token/go*d/ → "gd", "god", "good"
+1 or more of the preceding token/go+d/ → "god", "good" (not "gd")
?0 or 1 (optional)/colou?r/ → "color" or "colour"
{n,m}Between n and m occurrences/\d{2,4}/ → 2 to 4 digits
(…)Capture group — accessible via $1, $2/(\w+)@/ captures username
(?:…)Non-capturing group (group without capture)/(?:https?):\/\//
[abc]Character class — any of a, b, c/[aeiou]/ matches vowels
[^abc]Negated class — anything except a, b, c/[^aeiou]/ matches consonants
a|bAlternation — matches a or b/cat|dog/ → "cat" or "dog"
FAQ

Frequently Asked Questions

1How do I test a regex pattern online?
Paste your pattern and test string here. Matches highlight in real time. The results table shows every match, its index position, and any capture groups — no clicking required.
2What is the g flag in JavaScript regex?
The g (global) flag makes the regex find all matches in the string instead of stopping after the first. Without g, only the first match is returned. Most search and replace scenarios require g.
3How do I use capture groups in regex replace?
Wrap the parts to capture in parentheses: (\\w+). In the replacement string, reference them with $1, $2. For example, pattern (\\w+)\\s(\\w+) with replacement $2 $1 swaps two words.
4What is the difference between + and * in regex?
* matches zero or more occurrences — it can match nothing. + matches one or more — it requires at least one character. Use + when the character must appear, * when it is optional.
5What does \d mean in regex?
\\d matches any digit character — equivalent to [0-9]. Use \\d+ for one or more digits, \\d{4} for exactly four digits. \\D (uppercase) matches any non-digit.
6How do I make a regex case-insensitive?
Add the i flag. With i, the pattern /hello/i matches "Hello", "HELLO", "hElLo". Toggle it in the flags row above the pattern input.
7What is a regular expression?
A regular expression (regex) is a sequence of characters that defines a search pattern. Regex patterns can match, extract, validate, or replace text. They are supported natively in JavaScript, Python, Java, Go, and most other programming languages.
8What is the difference between global and non-global regex flags?
Without the g (global) flag, regex returns only the first match. With g, all matches are returned. In JavaScript, string.matchAll() requires the g flag and returns an iterator of all matches with capture group details.
9How do I match a regex in JavaScript?
Use str.match(/pattern/g) to return all matches, or regex.exec(str) in a loop for match details. regex.test(str) returns a quick true/false.
10How do I use regex in Python?
Import the re module. Use re.findall() to return all matches, re.search() to find anywhere, and re.sub() to replace matches.
11How do I use named capture groups?
Named groups use (?<name>pattern) in JavaScript and Python. Access via match.groups.name in JavaScript or match.group("name") in Python.
12What is a lookahead in regex?
Positive lookahead (?=...) asserts what must follow without including it in the match. Negative lookahead (?!...) asserts what must not follow. They do not consume characters.
13How do I validate an email with regex?
A common pattern is /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/. For production validation, supplement regex with a DNS MX record lookup.
14What is the difference between greedy and lazy quantifiers?
Greedy quantifiers (*, +) match as much as possible. Lazy quantifiers (*?, +?) match as little as possible. Use lazy when extracting delimited content like HTML tags.
Learn more

Developer Guides

Feedback for regex_tester

Tell us what's working, what's broken, or what you wish we built next — it directly shapes our roadmap.

You make the difference

Good feedback is gold — a rough edge you hit today could be smoother for everyone tomorrow.

  • Feature ideas often jump the queue when lots of you ask.
  • Bug reports with steps get fixed faster — paste URLs or examples if you can.
  • Name and email are optional; we won't use them for anything except replying if needed.

Stay Updated

Get the latest tool updates, new features, and developer tips delivered to your inbox.

What you'll get
  • Product updates & new tools
  • JSON, API & developer tips
  • Unsubscribe anytime — no hassle

Get in touch

Feature ideas, bugs, or a quick thanks — we read every message.