Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path
Regex Tester
An interactive regular-expression tester. Type a pattern and flags, paste your test text, and see all matches highlighted with their positions, plus every numbered and named capture group. Explains the flags and common tokens, and runs entirely in your browser so nothing is sent anywhere.
2 matches
https://vibeengines.comat 61https2vibeengines.comschemehttpshostvibeengines.com
http://example.orgat 341http2example.orgschemehttphostexample.org
A regular expression is a small language for describing shapes of text. Instead of writing code to scan characters, you write a pattern and the engine finds every substring that fits it. The hard part is seeing what a pattern actually matches rather than what you meant, and that is what this tester shows as you type.
What it computes
The tool builds new RegExp(pattern, flags) with your browser’s JavaScript engine, using the flags you switch on:
| Flag | Name | Effect |
|---|---|---|
g | global | Find every match; without it only the first is listed |
i | ignoreCase | Letters match regardless of case |
m | multiline | ^ and $ match at each line break |
s | dotAll | . also matches newlines |
A handful of pieces carry most patterns: character classes such as \d for a digit, \w for a letter, digit or underscore, and [a-z] for a range; quantifiers *, +, ? and {2,4} for how many; anchors ^ and $ for where; and | for either-or.
With g on, it calls exec repeatedly, collecting each match’s text and start index (counted from 0 in UTF-16 code units). If a match is empty, it moves forward one position so a pattern like a* cannot loop forever, and it stops after 10,000 matches. For each match it lists the numbered groups that took part, then the named groups. A syntax error shows the engine’s own message instead of results.
A worked example
The default pattern is (?<scheme>https?)://(?<host>[\w.-]+) with the g flag, run against two lines of text mentioning three URLs.
https?matcheshttpwith an optionals, captured as scheme.://is matched literally.[\w.-]+takes one or more letters, digits, underscores, dots or hyphens, captured as host. It stops at the first character outside that set, such as a slash or a space.
The result is 2 matches:
| Match | Index | Groups shown |
|---|---|---|
https://vibeengines.com | 6 | 1 = https, 2 = vibeengines.com, scheme = https, host = vibeengines.com |
http://example.org | 34 | 1 = http, 2 = example.org, scheme = http, host = example.org |
Two things did not match, and both are instructive. The /docs path is outside the host class, so the second match ends at .org. And ftp://nope fails because the scheme must be http or https. Switch g off and only the first match is listed.
Assumptions and limits
- JavaScript semantics. Other engines differ on lookbehind, Unicode classes, possessive quantifiers and more, so test in the target language too.
- Four flags. The
u,v,yanddflags are not offered, so a Unicode property escape such as\p{L}silently matches the literal textp{L}instead of any letter. - No replace or split. The tool lists matches and groups only.
- Runs on the page. A catastrophically backtracking pattern can freeze the tab, because matching is not timed out.
How to use the result
- Test the negatives. Paste strings that must not match, as the
ftpline does here, not only the ones that should. - Prefer named groups for anything you extract; code that reads
groups.hostsurvives a pattern edit that renumbers groups. - Be specific. Narrow character classes and anchors beat
.*for both correctness and speed. - Do not parse everything with regex. URLs, HTML and email addresses have edge cases a pattern misses; use a real parser when correctness matters.
When to use it, and when not
Use it while you write a pattern: paste real samples, including the lines that must not match, and edit until the match list is exactly right. It is equally good for reading a pattern someone else wrote, because the group list shows what each pair of parentheses captures, and for checking how a flag changes the result before it goes into code.
Reach for something else when the pattern will run in another engine, when speed matters, or when the input has structure. The tester runs JavaScript semantics and times nothing, so a pattern that looks fine here can behave differently in Python or Go, and can still be slow on a long adversarial input. For JSON, HTML, CSV with quoted fields or URLs, a parser is shorter and correct.
For a search-and-replace, settle the match list here first, then run the replace in the browser console: in a JavaScript replacement string $1 inserts group 1 and $<host> inserts a named group, so "$<host>" with the default pattern turns each URL into its bare host.
Trade-offs and limits
Most patterns port between engines unchanged. These are the differences that bite, all checkable in each language’s documentation:
| Feature | JavaScript, as tested here | Elsewhere |
|---|---|---|
$ without m | Only at the very end | Python also matches before a final newline, so ^abc$ matches "abc\n" |
\d | ASCII 0–9 only | Python 3 matches any Unicode digit, such as Arabic-Indic ٣ |
\w | ASCII letters, digits, underscore | Python 3 includes accented letters such as é |
| Lookbehind | Any length | Python requires fixed width; Go’s RE2 has no lookaround at all |
| Backreferences | Supported | Not in RE2, which in exchange guarantees linear-time matching |
| Named groups | (?<name>…) | Python’s re writes (?P<name>…) |
| Match index | UTF-16 code units | Python counts code points: in 😀 https://a.io the match starts at 3 here and at 2 in Python, because the emoji is two UTF-16 units |
The tester also says nothing about cost. A backtracking engine, which JavaScript’s is, can try every way of splitting the input between nested quantifiers. ^(a+)+$ can split a run of n letters 2n−1 ways, so against 30 a’s followed by a b it may explore up to 536,870,912 splits before reporting no match, and the tab hangs. ^a+$ matches the same strings in one linear pass. If a pattern stalls here on a short input, rewrite it until no two quantifiers can claim the same characters.
A routine that catches most bugs before they ship: paste the strings that must match, the strings that must not, and the edges, an empty line, a very long line and non-ASCII text. Read the match list and the groups for each. Then copy the pattern into the target language with the same samples, because the table above is where ported patterns quietly change meaning.
Common mistakes
- Reusing a global regex with
test. A regex withgkeepslastIndexbetween calls, so/a/g.test("a")on one object returns true, then false, then true. Dropgfor yes/no checks, or resetlastIndex. - Losing backslashes in a string. This tool takes the pattern raw. Pasted into a JavaScript string as
new RegExp("\d+"), the\dcollapses todand the pattern matches the letter d. In a string literal every backslash must be doubled. - A hyphen in the middle of a class.
[+-.]is a range from+to., which also includes the comma. Put a literal hyphen first or last, as the default pattern’s[\w.-]does. [A-z]for letters. The range runs through six ASCII symbols between Z and a:[ \ ] ^ _and the backtick. Write[A-Za-z].- Validating with a partial match.
/\d{4}/accepts"12345"because four digits occur inside it. A validator needs^and$around the whole pattern.
Check yourself
With g on, how many matches does a* find in baaa?
Three. An empty match at index 0, before the b; then aaa at index 1; then another empty match at index 4, the end of the string. After each empty match the tool moves forward one position, which is what stops the loop.
The text is 12, ab and 345 on three lines. What does ^\d+$ find with g, and with g and m?
With g alone, nothing: ^ and $ mean the whole string, which contains letters and newlines. With m they match at each line, so there are two matches: 12 at index 0 and 345 at index 6.
What does the default pattern capture as host from https://api.example.com:8080/v1?
api.example.com. The colon is outside [\w.-], so the host stops there, and the port and path are not captured. Adding (?::(?<port>\d+))? after the host would capture 8080.
Pattern (a)|(b) against b: which groups are listed?
Only group 2, with value b. Group 1 did not take part in the match, so it is undefined and the tool leaves it out rather than showing it empty.
/docs.How it works
- Uses the browser’s native ECMAScript regex engine.
- Shows every match with its start index.
- Lists numbered and named capture groups per match.
- Toggle g / i / m / s flags and see results update live.
Frequently asked questions
Which regex flavor does this use?
It uses the JavaScript (ECMAScript) regular-expression engine built into your browser, so the syntax matches what you would write in JavaScript, TypeScript and Node. Most everyday patterns are portable, but features differ between engines. JavaScript supports named groups, lookahead and, in modern engines, lookbehind, but not PCRE features such as recursion, possessive quantifiers or atomic groups. If the pattern will run in Python, Go, Java or PCRE, test it there as well for edge cases.
What do the flags g, i, m and s do?
g, global, finds every match instead of stopping at the first. i, ignore case, makes letters match regardless of case. m, multiline, makes the caret and dollar anchors match at the start and end of each line rather than only the whole string. s, dotAll, lets the dot match newline characters too. The tester rebuilds the expression with whichever flags are on and re-runs it instantly, so you can see the effect of each one on your own text.
What is a capture group?
Parentheses in a pattern create a capture group, a part of the match you can extract separately. Groups are numbered left to right by their opening parenthesis, and a group can also be given a name by starting it with a question mark and the name in angle brackets. This tool lists every group for each match, numbered groups first and then named ones, so a named group appears under both labels. Start a group with ?: when you need grouping without capturing.
Why does my pattern match more or less than I expected?
The usual causes are greedy quantifiers, missing anchors and unescaped special characters. A star or plus grabs as much as it can, so .* can run past the end you meant; add a question mark to make it lazy, or use a narrower character class. Without a caret and dollar, a pattern can match inside a longer string. A plain dot matches any character, so escape it with a backslash to mean a literal period, as in example\.com.
How do I avoid catastrophic backtracking?
Patterns with nested quantifiers over overlapping alternatives, such as (a+)+ or (.*)*, can make the engine explore an exponential number of paths on an input that almost matches, freezing the page; on a server this is a denial-of-service risk known as ReDoS. Prefer specific character classes to .*, avoid nested repetition, and anchor the pattern. If a pattern is slow here on a modest input, it will be far worse on a server processing untrusted text.