Free · Live · Nothing is uploaded

Regex tester.
Live, fast, private.

Write a pattern, see matches highlighted instantly, inspect capture groups, preview replacements and export code.

Regular expression
//
Test string
0 characters · 1 line
No pattern yet.

How to use the regex tester

Three steps, no account.

Write your pattern

Type a regular expression and toggle the flags you need. Errors show right away.

Add test text

Matches highlight live as you type. Click any match to jump to it in your text.

Replace and export

Preview replacements, copy the code for JavaScript, Python or PHP, or share a link.

Built for real work

Everything you need to build and debug patterns.

Live highlightingSee every match instantly, with zero-length matches marked.
Freeze-proofRuns in a worker and stops slow patterns after 1.5 seconds.
Share a linkPattern, flags, text and replacement stored in the link.
PrivateNothing leaves your browser. No signup, no tracking of your text.
Updated November 2026

What is a regex tester?

A regex tester is a tool that lets you write a regular expression (regex) and instantly see what it matches in a piece of sample text. Instead of running your code again and again to check a pattern, you can watch matches highlight live, inspect capture groups and try replacements before you put the pattern into your project.

This free online regex tester uses the JavaScript (ECMAScript) regular expression engine in your browser. It highlights every match, lists the position and groups of each match, previews search and replace results, and generates ready-to-use code for JavaScript, Python and PHP. Your pattern and text are processed locally and are never uploaded.

Regex syntax cheat sheet

These are the building blocks you will use in almost every pattern. Click any token in the Quick reference panel above to insert it into your expression.

TokenMeaningExample
.Any character except a line break (use the s flag to include line breaks)a.c matches "abc", "a-c"
\d \DA digit / a non-digit\d{3} matches "123"
\w \WA word character (letter, digit, underscore) / anything else\w+ matches "user_1"
\s \SWhitespace (space, tab, newline) / non-whitespace\s+ matches runs of spaces
\b \BA word boundary / not a word boundary\bcat\b matches "cat" but not "concat"
^ $Start / end of the text (or of each line with the m flag)^\d+$ matches digits only
* + ?0 or more / 1 or more / 0 or 1 of the previous itemcolou?r matches "color" and "colour"
{n} {n,m}Exactly n / between n and m repeats\d{2,4} matches 2 to 4 digits
[abc] [^abc]Any one of the listed characters / any character not listed[A-Za-z] matches one letter
(…)A capture group, available as $1, $2 and so on(\d+)-(\d+)
(?:…)A non-capturing group, used only for grouping(?:ab)+
(?<name>…)A named capture group, available as $<name>(?<year>\d{4})
a|bAlternation: match a or bcat|dog
\1A backreference to the first capture group(\w)\1 matches "ll" in "hello"
(?=…) (?!…)Lookahead: followed by / not followed by\d+(?= USD)
(?<=…) (?<!…)Lookbehind: preceded by / not preceded by(?<=\$)\d+

To match a character that has a special meaning, put a backslash in front of it. For example, \. matches a literal dot and \( matches a literal opening parenthesis.

Common regex examples you can copy

Use these patterns as a starting point. Open the Examples panel in the tester to load a version with sample text, then adjust it for your own data.

Use casePatternMatches
Email address[\w.+-]+@[\w-]+(?:\.[\w-]+)+hello@example.com
URLhttps?:\/\/[^\s/$.?#].[^\s]*https://toolforge.com/regex-tester
Date (YYYY-MM-DD)\d{4}-\d{2}-\d{2}2026-11-19
Time (24 hour)([01]\d|2[0-3]):[0-5]\d09:30, 23:59
IPv4 address (loose)\b(?:\d{1,3}\.){3}\d{1,3}\b192.168.1.1
Hex color#(?:[0-9a-fA-F]{3}){1,2}\b#fff, #4f46e5
Digits only^\d+$20261119
Trim leading and trailing spaces^\s+|\s+$" text "
Repeated words\b(\w+)\s+\1\b"the the"
HTML tag<\/?[a-z][^>]*><div class="a">
Password with upper, lower and digit (8+ chars)^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$Passw0rd
Hashtag#\w+#regex
Tip: email, URL and phone patterns are practical filters, not full validators. For critical checks such as sending email, always confirm on the server or by sending a verification message.

Regex flags explained

Flags change how the whole pattern behaves. You can toggle them with the buttons under the pattern box.

FlagNameWhat it does
gGlobalFinds all matches instead of stopping after the first one.
iIgnore caseTreats uppercase and lowercase letters as the same.
mMultilineMakes ^ and $ match at the start and end of every line.
sDot allLets . match line breaks too.
uUnicodeEnables full Unicode support, including characters outside the basic plane and \p{…} properties.
yStickyMatches only at the exact position where the last match ended.

Greedy vs lazy matching and backtracking

By default, quantifiers such as *, + and {n,m} are greedy: they match as much text as they can. Adding a ? after the quantifier makes it lazy, so it matches as little as possible.

For example, on the text <b>one</b> and <b>two</b>, the greedy pattern <b>.*</b> returns one long match from the first tag to the last, while the lazy pattern <b>.*?</b> returns two separate matches.

What is catastrophic backtracking?

When a pattern fails, the engine goes back and tries other ways to match. With nested or overlapping quantifiers, such as (a+)+$, the number of attempts can grow exponentially, and a short input can freeze a program. To avoid this, remove nested quantifiers, make alternatives mutually exclusive, use specific character classes instead of .*, and anchor your pattern. This tester runs matching in a background worker and stops it after 1.5 seconds, so you can experiment safely.

Common regex mistakes and how to fix them

  • Forgetting to escape special characters. Characters like . * + ? ( ) [ ] { } ^ $ | \ have special meanings. Escape them with a backslash to match them literally.
  • Using .* everywhere. It is greedy and often matches too much. Prefer a lazy quantifier or a negated class such as [^"]*.
  • Missing the global flag. Without g, only the first match is returned.
  • Forgetting anchors for validation. To check that the whole string matches, use ^ and $. Without them, a partial match is enough.
  • Using ^ and $ on multi-line text. Turn on the m flag if you want them to work per line.
  • Expecting the same behavior in every language. Engines differ. For example, named groups are written (?<name>…) in JavaScript and (?P<name>…) in Python.

Using your regex in JavaScript, Python and PHP

The Code tab generates a snippet for your current pattern, flags and text. Here is the basic idea in each language, using a date pattern.

JavaScript

const re = /(\d{4})-(\d{2})-(\d{2})/g;
const text = "Released 2026-11-19";
for (const m of text.matchAll(re)) {
  console.log(m[0], m[1], m[2], m[3]);
}

Python

import re

text = "Released 2026-11-19"
for m in re.finditer(r"(\d{4})-(\d{2})-(\d{2})", text):
    print(m.group(0), m.groups())

PHP

$text = "Released 2026-11-19";
preg_match_all('/(\d{4})-(\d{2})-(\d{2})/', $text, $matches, PREG_SET_ORDER);
print_r($matches);

What is regex used for?

  • Form validation: check emails, phone numbers, postal codes and usernames before submitting.
  • Search and replace: rename files, reformat dates or clean up text in editors and scripts.
  • Data extraction: pull IDs, prices, links or hashtags out of logs, web pages and documents.
  • Data cleaning: remove extra spaces, strip HTML tags or normalize separators.
  • URL routing and rewrites: match paths in web servers and frameworks.
  • Log analysis: filter errors and timestamps from large log files.

Regex is powerful, but it is not the best tool for everything. For nested structures such as full HTML or JSON, use a proper parser. Looking for other utilities? Browse all developer tools, or try our image compressor and JPG to PDF converter.

FAQs

Which regex flavor does this use?

The JavaScript (ECMAScript) engine in your browser. The Code tab converts common patterns for Python and PHP, but always test in the target language for edge cases.

Is my text sent to a server?

No. Everything runs in your browser, so your pattern and test text stay on your device.

Why does it say the pattern took too long?

Some patterns cause catastrophic backtracking, for example nested quantifiers like (a+)+$. Matching runs in a background worker and is stopped after 1.5 seconds so the page never freezes.

How do I share my regex?

Click Copy link. The link contains your pattern, flags, test text and replacement.

What do the flags mean?

g finds all matches, i ignores case, m makes ^ and $ work per line, s lets the dot match newlines, u enables Unicode mode, and y matches only at the current position.

What is a regular expression?

A regular expression, or regex, is a short pattern that describes a set of strings. It is used to search, validate, extract and replace text in programming languages, code editors and command-line tools.

How do I match an email address with regex?

A practical pattern is [\w.+-]+@[\w-]+(?:\.[\w-]+)+. It catches most normal addresses, but no regex can fully validate an email. Confirm important addresses by sending a verification message.

What is the difference between greedy and lazy matching?

Greedy quantifiers such as .* match as much text as possible. Lazy quantifiers such as .*? match as little as possible. Lazy matching is useful when you want the shortest result between two markers, for example inside HTML tags or quotes.

What are capture groups and named groups?

Parentheses create a capture group that saves part of the match, which you can reuse as $1, $2 and so on. A named group, written (?<name>...), gives that part a readable name such as $<name>. The Matches tab shows every group for each match.

Can I use this tester for Python or PHP regex?

The tester uses the JavaScript engine, but most basic syntax works the same in Python and PHP. The Code tab converts your pattern for both languages. Advanced features such as lookbehind and named groups can differ, so test in the target language too.

Is this regex tester free to use?

Yes. It is completely free, needs no signup, and works on phones, tablets and computers. All processing happens in your browser.

More tools

Related image, PDF and developer tools.

See developer tools →

Need a tool we don't have yet?

Tell us what you need and we will add it to the list.

Contact us