Skip to content
Regex тестер
Tools

Regex тестер

Ново

Тестирајте регуларне изразе уз истицање подударања уживо, групе за хватање и преглед замене.

/ /
0 matches

Match highlight

 

Matches & groups

Replace

 
Regex cheatsheetquick reference
\d \D
digit / non-digit
\w \W
word char / non-word char
\s \S
whitespace / non-whitespace
.
any char (except newline without s flag)
^ $
start / end of string (line with m flag)
\b \B
word boundary / non-boundary
[abc] [^abc]
char set / negated set
[a-z0-9]
char range
a* a+ a?
0+ / 1+ / 0 or 1
a{3} a{2,5} a{2,}
exactly 3 / 2–5 / 2 or more
a*? a+?
lazy (non-greedy) quantifiers
(abc)
capture group → $1
(?<name>abc)
named group → $<name>
(?:abc)
non-capturing group
a|b
alternation (a or b)
\1 \k<name>
backreference
(?=abc) (?!abc)
lookahead / negative lookahead
(?<=abc) (?<!abc)
lookbehind / negative lookbehind
\n \t \r
newline / tab / carriage return
\. \* \\
escaped literal . * \

Runs entirely in your browser. Nothing is uploaded.

Test regular expressions live, in real JavaScript

This free regex tester highlights every match the instant you type, using your browser's genuine JavaScript regex engine — so what matches here is exactly what will match in your frontend code or Node.js. Toggle any of the six flags (g, i, m, s, u, y), and invalid patterns show the actual engine error message instead of failing silently.

Below the live highlight you get a full match list — every match with its position plus all capture groups, numbered and named — and a replace panel that previews substitutions with $1, $<name> and $& backreferences as you type. When the pattern works, click Copy as JavaScript to grab ready-to-paste code.

A focused alternative to regex101.com and regexr.com

Heavyweight testers like regex101.com support PCRE, Python, Golang, and .NET flavors alongside JavaScript — useful when you're comparing engines, but often more than you need when you just want to debug a JS pattern. regexr.com surfaces community patterns and provides a reference guide. Both require navigation through multiple tabs to get from a match result to a replace preview.

This online regex tester answers the three questions that matter most day-to-day on one clean screen: does it match, what did it capture, and what does the replace produce? No flavor selection, no account, no upload. Unlike regexpal.com (which shows highlights only) or debuggex.com (which focuses on visual railway diagrams), this tool adds per-match capture-group extraction and live replace preview with backreference support.

Common regex patterns, one click away

The built-in library inserts battle-tested patterns with realistic sample text: email address, URL, IPv4 address, ISO date, 24-hour time, hex color, URL slug, international phone number, number (integer/float) and HTML tag. Each loads with valid and invalid examples so you can see precisely where the pattern's edges are.

They're starting points, not gospel — tweak them in place and watch the highlight respond. The samples deliberately include edge cases (like 999.999.1.1 for IPv4) so you learn what each pattern rejects, not just what it accepts. This is far faster than copying a pattern from Stack Overflow and guessing whether it handles your edge cases.

Capture groups, lookarounds, and all six flags — fully supported

Modern JavaScript regex has powerful features: named groups (?<year>\d{4}), lookahead (?=…) and lookbehind (?<=…), Unicode property escapes with the u flag, and sticky matching with y. This tester supports all of it, because it is the JavaScript engine. The match panel breaks out each group per match so extraction logic is verifiable at a glance.

The m flag demo is a favorite: with it, ^ and $ anchor to every line of your test text — paste a log file and watch a ^ERROR pattern light up each offending line. Toggle s to make . match newline characters inside multiline strings without workarounds. Every result you see here is the same one your code will produce.

Learn regex faster with the built-in cheatsheet

The collapsible regex cheatsheet covers the tokens you'll reach for daily — character classes (\d \w \s), anchors (^ $ \b), quantifiers (* + ? {n,m} and their lazy forms), groups, alternation, backreferences and all four lookarounds. Keep it open while you experiment; seeing a token's effect highlighted live is the fastest way regex actually sticks.

Start simple: match a literal word, add a character class, then a quantifier, then a group. Five minutes of live feedback in a regex playground teaches more than an hour of reading syntax tables. Works on mobile too — the layout adapts for smaller screens, so you can debug patterns on iPhone or Android without any app install.

NFA vs DFA: why backtracking exists and how it can hurt you

Nearly every programming language regex engine — JavaScript, Python, Ruby, Java, PHP — is built on a Non-deterministic Finite Automaton (NFA). An NFA tries each alternative in order, remembering where it was so it can backtrack and try another path if a branch fails. This approach is what makes features like backreferences and lookaheads possible: a Deterministic Finite Automaton (DFA) — the engine used by tools like awk and egrep — can guarantee linear-time matching but cannot support those constructs because it processes each character exactly once without memory of earlier choices.

The cost of the NFA approach is catastrophic backtracking. The classic illustration is the pattern (a+)+ applied to a string like aaaaab. The outer group can split the inner matches in an exponential number of ways before concluding no match exists, causing the engine to explore 2ⁿ paths for a string of length n. This is the mechanism behind ReDoS (Regular Expression Denial of Service) attacks: a server that validates user input with a vulnerable pattern can be frozen by a carefully crafted string of a few hundred characters. The fix is to eliminate ambiguity — use atomic groups or possessive quantifiers where supported, avoid nested quantifiers over the same characters, and prefer negated character classes (for example [^,]* instead of .*? before a comma) to give the engine a deterministic stopping point.

Testing your pattern against a deliberately malicious input is easy in this tester: paste a long string of repeated characters that your pattern is designed to reject, switch to single-character stepping in your browser DevTools if the engine hangs, then refactor until the rejection is instant. Spotting the problem here costs milliseconds; spotting it in production can cost an outage.

Lookaheads and lookbehinds: match with context, consume nothing

Lookaround assertions let you attach conditions to a match without including the surrounding text in what the engine consumes. A positive lookahead (?=...) says 'the current position must be followed by this'; a negative lookahead (?!...) says 'must NOT be followed by this'. Their mirror images, positive lookbehind (?<=...) and negative lookbehind (?<!...), impose the same constraint on what precedes the match. Because lookarounds are zero-width — they assert a condition but do not advance the cursor — they're ideal when you need context to decide whether to match but don't want that context captured or consumed.

Two concrete use cases illustrate why they're indispensable. Password validation often requires that a string contain at least one digit AND at least one letter. Rather than enumerating every combination, you write two separate lookaheads anchored at the start: ^(?=.*\d)(?=.*[A-Za-z]).+$ — the engine checks both conditions at position zero before committing to the rest of the match. Price extraction shows the lookbehind: to pull numeric values from text like '€12.99' and '$4.50' without capturing the currency symbol, use (?<=[$€£])\d+\.\d{2}. The symbol is required to be present but is not included in what match() returns.

JavaScript's V8 engine has supported lookbehinds since Chrome 62 (2017), so they're safe to use in any modern browser or current Node.js version. One important nuance: inside a lookbehind, the pattern is matched right-to-left, which means some complex patterns behave unexpectedly — variable-length lookbehinds in particular can produce surprising results. Paste your pattern here and inspect each match's start/end index to verify the cursor position behaves as you intend.

Named capture groups and non-capturing groups

By default, every set of parentheses in a pattern is a numbered capture group — the first opening paren is group 1, the second is group 2, and so on. This works fine for small patterns but becomes brittle the moment the pattern grows: insert a new group near the start and every $2 reference in your replacement string shifts by one. Named capture groups solve this. In JavaScript and most PCRE-compatible languages you write (?<name>...); in Python you write (?P<name>...). The captured value is then accessible by name rather than position: match.groups.year in JavaScript or match.group('year') in Python. A date pattern like (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) makes the intent of each group self-documenting, survives pattern refactors without breaking downstream code, and lets you reference the capture in a replacement as $<year>.

When you need grouping for structure or alternation but have no interest in capturing the matched text, use a non-capturing group (?:...). It behaves identically to a capturing group for matching purposes but does not allocate a slot in the match array, which keeps your group numbering clean and saves the engine a tiny amount of memory per match. A pattern like (?:https?|ftp):// groups the protocol alternatives without polluting the capture list. As a rule of thumb: use (?:...) whenever you're grouping for precedence or alternation and (?<name>...) whenever you intend to extract the value — reserve plain (...) only when you need the group numbered for a quick backreference in a one-off replacement.

The match panel in this tester lists every named and numbered group per match, making it straightforward to verify your extraction logic. If a group shows undefined, either the branch that contained it did not participate in the match (a normal result in alternation patterns) or you accidentally used a non-capturing group where a capturing one was intended. Both conditions are immediately visible here before you commit the pattern to code.

Common practical patterns worth knowing

Certain patterns appear in nearly every codebase, and understanding why they're written the way they are is as important as memorising the syntax. Email is the canonical example of a deceptively hard problem: the full grammar in RFC 5321 permits characters like +, quotes, and even spaces in the local part, which means a truly compliant regex would run to hundreds of characters and still fail edge cases. The pragmatic solution is to validate loosely — ^[^\s@]+@[^\s@]+\.[^\s@]+$ — and confirm deliverability by sending an actual message. A UUID (version 4) is reliably matched with [0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12} (case-insensitive flag recommended). An ISO 8601 date like 2024-06-15 uses \d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]) — the alternations in each segment enforce calendar-plausible ranges without needing a parser.

A URL slug — the lowercase hyphenated string in a web address — is one of the simplest reliable patterns: ^[a-z0-9]+(?:-[a-z0-9]+)*$. An IPv4 address is commonly written as four groups of (?:25[0-5]|2[0-4]\d|[01]?\d\d?) joined by escaped dots; the alternation in each octet enforces the 0–255 range that a naive \d{1,3} cannot. Phone numbers are a case where regex is the wrong primary tool: number formats vary so drastically by country that a single international pattern becomes unmaintainable. The recommended approach is to strip all non-digit characters with [^\d+], then validate length and country prefix in code. Credit card numbers can be checksum-verified in JavaScript with the Luhn algorithm — a regex can confirm the digit count and spacing but cannot validate the Luhn sum, so use a regex to sanitise input and a short function to verify authenticity.

These patterns are worth internalising not because memorised regex is faster to type, but because understanding the structure of each one — why the email regex punts on full RFC compliance, why the IPv4 regex uses alternation rather than a simple \d{1,3} — sharpens your instinct for when regex is the right tool versus when a proper parser or library function will serve you better. Load any of these from the built-in library, then deliberately break them with edge-case inputs to see exactly where each pattern's boundaries lie.

Frequently asked questions

What is a regex tester?

A regex tester is an interactive tool where you type a regular expression and some sample text, and it instantly highlights every match. This tester shows capture-group values — numbered and named — supports all six JavaScript flags (g, i, m, s, u, y), provides a live replace preview with backreferences, a common-pattern library, and a full cheatsheet. You can debug and verify patterns before putting them in code, all without installing anything or creating an account.

How does this regex tester compare to regex101.com and regexr.com?

regex101.com and regexr.com are excellent but can feel dense — multiple flavors, a full debugger, quizzes, community patterns. This tester focuses on the JavaScript engine specifically and answers the three questions that matter most day-to-day: does it match, what did it capture, and what does the replace produce? It loads instantly, stores your work locally, runs entirely in your browser, and shares patterns via a URL-encoded link — no account needed on either tool. Unlike regex101 which supports PCRE, Python, and Golang flavors, this one runs your browser's native JavaScript engine so results are exact.

Is this different from regexpal.com or debuggex.com?

Yes. Regexpal offers simple highlighting but no capture group breakdown and no replace preview. Debuggex adds a visual railway diagram but lacks the common-pattern library. This tester adds per-match capture-group extraction, a live replace panel with $1/$<name>/$& backreference support, and a built-in pattern library with realistic sample text — all while running the genuine JavaScript engine so results match exactly what your code produces. Everything works offline with no upload required.

What does regex mean?

Regex is short for 'regular expression' — a string of characters that defines a search pattern. Regexes are used for matching, extracting, validating, and find-and-replace operations on text in virtually every programming language and text editor. The term dates back to the 1950s and mathematician Stephen Cole Kleene, but practical regex use exploded with the Perl language in the 1980s.

How do I test a regular expression in JavaScript?

In JavaScript you have several options: use regex.test(str) for a true/false check, str.match(regex) to get matched text, str.matchAll(regex) for all matches with group details, or regex.exec(str) to iterate matches one at a time. This tester runs all of that live as you type — and the 'Copy as JavaScript' button gives you the exact code for your pattern, ready to paste into your project.

What is a capture group in regex?

Parentheses ( ) create a capture group that stores whatever matched inside them, retrievable as $1, $2, etc. Named groups written (?<name>...) let you reference captures by name instead of number. Capture groups let you extract parts of a match — like the username and domain from an email address — or reuse them in replacements. The match panel in this tester lists every group's value per match, making it easy to verify your extraction logic before using it in production code.

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

g (global) finds all matches instead of stopping at the first; i (ignoreCase) makes matching case-insensitive; m (multiline) makes ^ and $ match at the start and end of every line rather than just the whole string; s (dotAll) makes the dot match newlines too; u (Unicode) enables full Unicode support and property escapes like \p{Letter}; y (sticky) anchors the match to lastIndex. All six flags are toggleable in this tester with a single click.

Is regex case sensitive by default?

Yes — /hello/ matches 'hello' but not 'Hello'. Toggle the i (ignoreCase) flag to make the pattern match regardless of letter case. This is a common source of bugs in validation logic — for example an email regex that fails to match 'User@Example.COM' because the i flag was forgotten.

What is the difference between match, test, and exec in JavaScript?

test() returns a boolean — use it when you just need to know if something matches. match() called on the string returns an array of matches or null. exec() called on the regex returns one detailed match at a time and advances through the string when the g flag is set. matchAll() returns every match with full group details in one call — it's usually the right choice for extraction work. This tester runs matchAll under the hood and surfaces all results in the match panel.

What is a lookahead or lookbehind in regex?

A lookahead (?=...) checks that a pattern follows the current position without consuming characters; a negative lookahead (?!...) checks the opposite. Lookbehind (?<=...) and (?<!...) do the same for what comes before. They're useful for conditions like 'match a number not followed by a percent sign' or 'match a word preceded by a dollar sign'. All four lookaround types work in this tester because modern JavaScript (V8) supports them fully.

Is regex the same in all programming languages?

No — regex flavors differ significantly. JavaScript, PCRE (used by PHP and Perl), Python's re module, .NET, Java, and Ruby each support different syntax and features. PCRE supports possessive quantifiers and atomic groups that JavaScript doesn't have; Python uses (?P<name>...) for named groups instead of (?<name>...); .NET adds balancing groups. This tester runs the genuine JavaScript/V8 engine, so results match exactly what your frontend code or Node.js will produce.

How do I use regex to find and replace text?

In JavaScript, str.replace(/pattern/g, 'replacement') swaps every match. Use $1 or $<name> in the replacement string to insert captured groups, and $& for the whole match. The Replace panel in this tester previews the result live as you type, so you can see the substitution before committing it to code. You can also use a function as the replacement argument for more complex transformations — useful for things like capitalizing every match.

What do \d, \w, and \s mean in regex?

\d matches any digit (0–9), \w matches a word character (letter, digit, or underscore), and \s matches whitespace (space, tab, newline). Their uppercase forms \D, \W, and \S match the opposite — everything that \d, \w, and \s don't match. The built-in cheatsheet lists these and every other common token with examples. Character classes are the building blocks of most real-world patterns.

Why is my regex matching too much (greedy matching)?

Quantifiers like * and + are greedy by default — they grab as much text as possible before giving any back. Add ? to make them lazy (.*?), which makes them grab as little as possible instead. Another option is to use a negated character class like [^"]* to stop at a specific delimiter. Paste your text into this tester and you'll see the greedy versus lazy difference highlighted side by side — it's the fastest way to understand what's happening.

Is this regex tester free, and can I share a pattern?

Free, no ads, no sign-up. 'Copy share link' encodes your pattern, flags, and test text into the URL so a teammate opens exactly what you're seeing — no account required on either end. Your work also auto-saves locally in your browser so it's there when you return. Unlike regex101 which requires a login to save and share patterns permanently, this tool gives you a shareable URL instantly.