Vibe Engines
YouTube

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.

//g

2 matches

  • https://vibeengines.comat 6
    • 1https
    • 2vibeengines.com
    • schemehttps
    • hostvibeengines.com
  • http://example.orgat 34
    • 1http
    • 2example.org
    • schemehttp
    • hostexample.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:

FlagNameEffect
gglobalFind every match; without it only the first is listed
iignoreCaseLetters match regardless of case
mmultiline^ and $ match at each line break
sdotAll. 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? matches http with an optional s, 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:

MatchIndexGroups shown
https://vibeengines.com61 = https, 2 = vibeengines.com, scheme = https, host = vibeengines.com
http://example.org341 = 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, y and d flags are not offered, so a Unicode property escape such as \p{L} silently matches the literal text p{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 ftp line does here, not only the ones that should.
  • Prefer named groups for anything you extract; code that reads groups.host survives 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.

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.