T

Text Machine

Powerful text tools, in your browser

Regex Tester

Build and test regular expressions against your own text in real time. See every match highlighted, inspect capture groups, and preview replacements — all in your browser.

Regular expression

/

/g

Flags

Test string
Replace with

Tip: enable the g flag to replace every match instead of only the first.

How to use Regex Tester

  1. 1

    Write your pattern

    Type a regular expression in the pattern field, then toggle the flag chips (g, i, m, and more) to control exactly how matching works.

  2. 2

    Add your test text

    Paste the text you want to search into the “Test string” box. Matches are highlighted instantly as you type or edit the pattern.

  3. 3

    Inspect the matches

    Review each match, its position in the text, and any capture or named groups in the results list to confirm the pattern behaves as expected.

  4. 4

    Replace or copy

    Enter a replacement to preview substitutions with $1-style backreferences, then copy the result straight into your code or document.

Regular Expressions in Practice: A Developer's Field Guide

What a regex really describes

A regular expression is a tiny pattern language for describing sets of strings. Instead of asking whether text equals a fixed value, you describe its shape — a sequence of digits, a word followed by an at sign and a domain, three letters then a dash — and the engine scans your text for every substring that fits. That single idea powers validation, search-and-replace, log parsing, tokenizing, and data extraction in nearly every language and editor.

This tester uses the JavaScript (ECMAScript) engine built into your browser, the same one Node.js and web apps use. So a pattern that matches here behaves identically in your application code, which makes it a faithful sandbox for building and debugging a pattern before you paste it into a project.

Character classes and the building blocks

Most of a pattern is just literal characters that match themselves, interspersed with a handful of special tokens. A character class in square brackets matches any one character from a set: a range of lowercase letters, a set of vowels, or a digit. The shorthand backslash-d matches a digit, backslash-w matches a word character (letters, digits, underscore), backslash-s matches whitespace, and a dot matches any character except a newline. Capitalize the shorthand to invert it — backslash-D is any non-digit.

These are the atoms you combine into everything else. A pattern for a hex color, for example, is an anchor for the hash sign followed by a character class of hex digits repeated; a pattern for a word is simply backslash-w repeated one or more times. Build patterns from these small pieces rather than reaching for one giant expression.

Anchors, quantifiers, and alternation

Anchors match positions rather than characters. The caret matches the start of the string (or the start of a line with the multiline flag) and the dollar sign matches the end; the word-boundary token backslash-b matches the edge between a word character and a non-word character, which is how you match a whole word without catching it inside a longer one. Quantifiers control repetition: the plus sign means one or more, the asterisk means zero or more, and the question mark means optional. You can also specify an exact count or a range using the brace form when you need, say, a value that repeats two to four times.

Alternation with the pipe symbol means or — a pattern of cat or dog matches either word. Wrap alternatives in parentheses to scope the choice. By default quantifiers are greedy, grabbing as much as they can; add a question mark after a quantifier to make it lazy and match as little as possible, which is the usual fix when a pattern meant to grab one tag swallows everything up to the last one on the line.

Capture groups and how to use them

Parentheses do double duty: they group part of a pattern and they capture what that part matched. After a match, the captured pieces are available as numbered groups — the first set of parentheses is group one, the next is group two — and the results list here shows each one so you can confirm you are pulling out exactly the fragment you intend. A pattern for an email-like string with separate parentheses around the local part, the domain, and the extension lets you read those three pieces back individually.

Named groups, written with the syntax that places a name in angle brackets right after the opening parenthesis, give those captures readable labels instead of bare numbers and appear in their own section. When you only want grouping without the capture overhead, a non-capturing group — an opening parenthesis followed by a question mark and a colon — keeps your group numbers clean. These captures are also what your replacement step references.

Flags change the whole match

Flags are modifiers that alter how the entire pattern is applied. Global finds every match instead of stopping at the first, which is essential for replacing all occurrences rather than just one. Ignore-case makes letters match regardless of capitalization. Multiline redefines the caret and dollar anchors to match at each line break instead of only at the very start and end of the input.

The remaining flags are situational but important. Dotall lets the dot match newline characters too, so a pattern can span lines. Unicode turns on full Unicode handling for code points beyond the basic range and for Unicode property escapes. Sticky anchors each match to the position right after the previous one, which is how tokenizers walk through input without skipping ahead. Toggle the flags here and watch the highlighted matches change to build intuition for each one.

Patterns you will write constantly

A few shapes come up again and again. Pulling all the integers out of a blob of text is backslash-d repeated one or more times with the global flag. A rough email check is one or more word characters, an at sign, one or more word characters, a literal dot, and a short run of letters — adequate for a quick sanity filter, though deliberately loose. Trimming or collapsing runs of whitespace, validating a slug of lowercase letters and dashes, and extracting the contents between two markers are all everyday jobs.

Resist the urge to validate truly complex formats with one monster pattern. Email and URL grammars in particular are notoriously hard to capture fully in a regex; for those, a loose pattern plus a real parser or a dedicated library usually beats an unreadable expression you will be afraid to touch in six months.

Catastrophic backtracking and how to avoid it

The engine's backtracking is what makes regex powerful, but it can also make a pattern explode. When two quantified parts of a pattern can match the same characters in many overlapping ways — a classic example is a group that is itself repeated, where the inner and outer repetition compete — the engine may try an astronomical number of combinations against a string that ultimately fails to match. On a long input this can lock up for seconds or hang entirely, and on a server it becomes a denial-of-service vector known as ReDoS.

The defenses are structural. Avoid nesting one quantifier inside another that can match the same thing, prefer more specific character classes over a permissive dot so each step has only one way to consume input, and anchor the pattern when you can. If you must test a risky pattern, do it here against a realistic worst-case string first, where a runaway pattern costs you a browser tab rather than a production outage.

Previewing replacements safely

Search-and-replace is where regex pays off daily, and the replacement field lets you preview the result before committing it anywhere. Reference your capture groups in the replacement with a dollar sign and the group number — dollar-one inserts whatever the first group matched — so you can reorder a date, reformat a name, or wrap matches in markup. Remember that without the global flag only the first match is replaced; enable global to transform every occurrence.

Everything runs locally in your browser using the native engine, so nothing you paste — log lines, source code, customer data — is uploaded, logged, or stored. That makes the tester a safe place to iterate on a real-world sample until both the matches and the replacement output are exactly right, then copy the finished pattern into your code with confidence.

Frequently asked questions

What is a regular expression?
A regular expression, or regex, is a compact pattern used to search, match, and transform text. Developers rely on them for input validation, search-and-replace, parsing, and data extraction in almost every programming language and text editor.
Which regex flavor does this tester use?
This tool uses the JavaScript (ECMAScript) regular expression engine built into your browser — the same engine used by Node.js and modern web apps. Patterns and flags behave exactly as they would in your own JavaScript code.
What do the flags mean?
g (global) finds every match instead of stopping at the first, i ignores letter case, m makes ^ and $ match at line breaks, s lets the dot match newline characters, u enables full Unicode handling, and y (sticky) anchors matching to a specific position in the text.
How do capture groups work?
Parentheses in your pattern create capture groups that pull out parts of each match. Numbered groups are referenced as $1, $2, and so on, while named groups written as (?<name>…) are listed separately, so you can extract exactly the data you need.
Is my data sent to a server?
No. Every match and replacement runs entirely in your browser using its native regex engine. Nothing you type is uploaded, logged, or stored, so the tester works offline and keeps your text completely private.

Related tools

Keep going with these handy tools

HTML to Text Converter

JSON Formatter

JWT Decoder

CSS Gradient Generator

CSS Box Shadow Generator

Text to HTML Converter