Command Palette

Search for a command to run...

Regex

Every Regex tool on Toolz.dev: 4 free utilities that run entirely in your browser. No signup, no uploads, no downloads.

A regular expression is a small pattern language for describing shapes of text, and it is the fastest way to do a job that would otherwise take twenty lines of string handling. It is also famously easy to write and hard to read, which is why testing one against real input matters more than getting it right in your head, and why the regex explainer exists: it takes a pattern apart token by token and says what each piece does, which is the faster way into an expression you inherited.

The regex tester compiles your pattern with the JavaScript engine and highlights every match and capture group as you type. The regex replace tool does the substitution half, with backreferences like $1 in the replacement. The email extractor is a specific, common case with the pattern already written and de-duplication built in.

Which regex tool for which task

Which regex tool for which task
TaskToolDetail
Test and debug a patternRegex TesterLive match highlighting, capture groups, all flags
Rewrite text with a patternRegex ReplaceBackreferences $1, $2 and named groups
Pull addresses out of textEmail ExtractorPractical pattern, de-duplicated output
Understand a pattern someone else wroteRegex ExplainerToken-by-token explanation in plain English

The flags, and what they change

Six flags do most of the work in JavaScript. The global flag g finds every match rather than the first, and is the one whose absence explains a replace that only changed one occurrence. The i flag makes matching case insensitive. The m flag changes what the anchors mean, so ^ and $ match at every line boundary instead of only at the start and end of the whole string. The s flag lets a dot match a newline, which it otherwise never does.

The two less familiar ones are worth knowing. The u flag enables full Unicode mode, which is what makes \u{1F600} and property escapes such as \p{L} work, and without it a pattern operates on UTF-16 code units and treats an emoji as two characters. The y flag anchors matching at the last index, which matters when writing a tokeniser. The regex tester exposes all of them, since a pattern that fails is as often a missing flag as a wrong pattern.

Capture groups and replacement

Parentheses do two things at once: they group for quantifiers, and they capture the matched text for later use. In a replacement, $1 refers to the first group, $2 to the second, and $<name> to a named group written as (?<name>...). Reformatting a date from 2026-08-22 to 22/08/2026 is one pattern with three groups and a replacement of $3/$2/$1, which is the regex replace tool at its most typical.

Where you want grouping without capturing, (?:...) is the non-capturing form, which keeps your group numbers stable as a pattern grows. And a dollar sign in a replacement is special, so a literal one has to be written as $$, which is the sort of thing that only surfaces when a price appears in your output as undefined.

Two ways a regex goes wrong in production

The first is catastrophic backtracking. A pattern with nested quantifiers, such as (a+)+$, can take exponential time on input that almost matches, because the engine tries every way of dividing the string before giving up. This is a real denial-of-service class, ReDoS, and it has taken down production services on user-supplied input. Testing against a long near-match, not just a positive example, is what surfaces it.

The second is trying to parse the wrong thing. HTML is not a regular language, so a pattern that extracts tags works on your sample and breaks on nested elements, comments and attributes containing angle brackets; use a parser. Email is the other perennial, where the RFC 5322 grammar is far larger than any usable pattern. The email extractor is explicit that it uses the practical pattern the industry settled on rather than the full grammar, which is the right trade for pulling addresses out of a block of text and the wrong one for deciding whether an address is valid. Everything here runs client-side, which matters when the text you are testing against is a log file.

Frequently asked questions

Why does my regex only replace the first match?
Because the global flag is missing. Without g, the engine stops at the first match, so a replacement changes one occurrence and leaves the rest. It is the single most common regex surprise, and the tester shows the flag string alongside the pattern for that reason.
What is the difference between the m and s flags?
The m flag changes the anchors: ^ and $ match at every line boundary rather than only at the start and end of the string. The s flag changes the dot, letting it match a newline, which it never does otherwise. They are independent, and a multi-line pattern often needs both.
How do I use a capture group in a replacement?
Reference it with a dollar sign and its number, so $1 is the first group and $2 the second, or $<name> for a group written as (?<name>...). To insert a literal dollar sign, write $$. Use (?:...) when you want grouping for a quantifier without creating a numbered capture.
What is catastrophic backtracking?
A pattern that takes exponential time on certain inputs because nested quantifiers give the engine an enormous number of ways to try to match. Patterns shaped like (a+)+ are the classic case, and on user-supplied input this becomes a denial-of-service vulnerability known as ReDoS. Test against long strings that nearly match, not only against strings that do.
Can I parse HTML with a regular expression?
No, and not for stylistic reasons: HTML is not a regular language, so nested elements, comments and attributes containing angle brackets defeat any pattern eventually. A regex is fine for pulling a value out of markup you control and generate; anything else needs a real parser.
Which regex flavour do these tools use?
JavaScript, the ECMAScript flavour, compiled with the browser own engine. It differs from PCRE and Python in places worth knowing: no possessive quantifiers, no recursion, and lookbehind is supported in current browsers but was a late addition. Patterns copied from a PHP or Python answer may need adjusting.