---
title: "JavaScript Regex Tester with Matches & Replace Preview"
description: "Test JavaScript regular expressions with live match highlighting, capture-group details, selectable flags, and replacement preview in your browser."
canonical_url: "https://webaloha.co/tools/regex-tester/"
markdown_url: "https://webaloha.co/tools/regex-tester.md"
date_modified: "2026-07-12T00:00:00.000Z"
---
# Regex Tester

Last updated: Jul 12, 2026

Write a regular expression and test it against your text in real time. See highlighted matches, capture groups, and replace output, with every flag at your fingertips, all running privately in your browser.

Refer a Client, Earn 10% or $100

Use our tools for client work? When a client needs a website, SEO, or AI-search visibility, send them our way and earn 10% or $100, whichever is greater.

[How Referrals Work 🤝](https://webaloha.co/refer-a-client/)

## How to Use the Regex Tester

1.  **Enter a pattern**, type your regular expression between the slashes.
2.  **Set flags**, toggle global, case-insensitive, multiline, and more.
3.  **Add test text**, matches highlight live as you type.
4.  **Inspect groups and replace**, review capture groups and preview replacements.

## Regex Quick Reference

-   `\d` digit, `\w` word char, `\s` whitespace, `.` any char.
-   `*` zero or more, `+` one or more, `?` optional, `{n,m}` range.
-   `^` start, `$` end, `\b` word boundary.
-   `(...)` capture group, `(?<name>...)` named group, `(?:...)` non-capturing.
-   `[abc]` character set, `[^abc]` negated set, `a|b` alternation.

## Regex Cheat Sheet

A reference for the regular expression tokens you will use most often. Examples use JavaScript (ECMAScript) syntax, the same engine this tester runs. Paste any example into the pattern field above to see it match.

### Character classes

| Token | Matches | Example |
| --- | --- | --- |
| **`.`** | Any character except a line break (any character including newlines with the `s` flag) | `a.c` matches "abc", "a c" |
| **`\d`** | Any digit, 0 to 9 | `\d\d` matches "42" |
| **`\D`** | Any non-digit character | `\D` matches "a", "-" |
| **`\w`** | Any word character: letters, digits, or underscore (`[A-Za-z0-9_]`) | `\w+` matches "user\_1" |
| **`\W`** | Any non-word character | `\W` matches "!", " " |
| **`\s`** | Any whitespace: space, tab, newline | `\s` matches " ", a tab |
| **`\S`** | Any non-whitespace character | `\S+` matches "word" |
| **`[abc]`** | Any one of the listed characters; ranges allowed with `-` | `[a-f]` matches "c" |
| **`[^abc]`** | Any single character not listed (negated class) | `[^0-9]` matches "x" |
| **`\.`** | A literal dot; backslash escapes any special character | `\.` matches "." only |

### Anchors and boundaries

| Token | Matches | Example |
| --- | --- | --- |
| **`^`** | Start of the string (or start of each line with the `m` flag) | `^Hi` matches "Hi there" |
| **`$`** | End of the string (or end of each line with the `m` flag) | `end$` matches "the end" |
| **`\b`** | A word boundary (position between `\w` and non-`\w`) | `\bcat\b` matches "cat" not "category" |
| **`\B`** | A non-word-boundary position | `\Bcat` matches "cat" in "scatter" |

### Quantifiers

| Token | Matches | Example |
| --- | --- | --- |
| **`*`** | Zero or more of the preceding token (greedy) | `ab*` matches "a", "abbb" |
| **`+`** | One or more of the preceding token (greedy) | `\d+` matches "2026" |
| **`?`** | Zero or one of the preceding token (optional) | `colou?r` matches "color", "colour" |
| **`{n}`** | Exactly n of the preceding token | `\d{4}` matches "2026" |
| **`{n,m}`** | Between n and m of the preceding token; `{n,}` means n or more | `\d{2,4}` matches "12" to "1234" |
| **`*?` `+?`** | Lazy versions: match as few as possible | `<.*?>` matches one tag, not all |

### Groups and alternation

| Token | Matches | Example |
| --- | --- | --- |
| **`(...)`** | Capturing group; stores the match as $1, $2, and so on | `(\d{4})-(\d{2})` captures year and month |
| **`(?:...)`** | Non-capturing group; groups without storing a reference | `(?:ab)+` matches "abab" |
| **`(?<name>...)`** | Named capturing group, referenced by name | `(?<y>\d{4})` captures as "y" |
| **`|`** | Alternation: match the expression before or after it | `cat|dog` matches "cat" or "dog" |

### Flags

| Flag | Effect |
| --- | --- |
| **`g`** | Global: find all matches, not just the first |
| **`i`** | Case-insensitive matching |
| **`m`** | Multiline: `^` and `$` match line starts and ends |
| **`s`** | Dotall: `.` also matches newline characters |
| **`u`** | Unicode: treat the pattern as Unicode code points |
| **`y`** | Sticky: match only at the current lastIndex position |

Regular expressions power validation, search, and data cleanup across almost every codebase. If you would rather offload tricky parsing, scraping, or data-transformation work, our team builds and maintains it as part of our [web design and development services](https://webaloha.co/web-design-services/).

Next steps

## Regex Tester related tools and articles

Continue with the closest follow-up checks and guides based on this tool's topic, crawl intent, and optimization workflow.

[![URL Encoder and Decoder Tool Online](https://webaloha.co/_astro/tool-url-encoder.CoZAQLWC_4tikr.webp?dpl=dpl_H1MtSCmk524EGpEs7Etp4HWKr3Ti)

URL Encoder / Decoder

](https://webaloha.co/tools/url-encoder-decoder/)[![Base64 Encode and Decode Tool Online](https://webaloha.co/_astro/tool-base64.EHOqbfE7_1sAvQw.webp?dpl=dpl_H1MtSCmk524EGpEs7Etp4HWKr3Ti)

Base64 Encode / Decode

](https://webaloha.co/tools/base64-encoder-decoder/)[![Cron Expression Generator Tool Online](https://webaloha.co/_astro/tool-cron.DmhVyCEe_Z2n4PBg.webp?dpl=dpl_H1MtSCmk524EGpEs7Etp4HWKr3Ti)

Cron Expression Generator

](https://webaloha.co/tools/cron-expression-generator/)[![HTML Entity Encoder and Decoder Tool Online](https://webaloha.co/_astro/tool-html-entity.CL9VLfLO_Z2noHs0.webp?dpl=dpl_H1MtSCmk524EGpEs7Etp4HWKr3Ti)

HTML Entity Encoder / Decoder

](https://webaloha.co/tools/html-entity-encoder-decoder/)[![SEO-Friendly URL Slug Generator Tool Online](https://webaloha.co/_astro/tool-slug-generator.DnHAaMOb_Z1qVUF2.webp?dpl=dpl_H1MtSCmk524EGpEs7Etp4HWKr3Ti)

URL Slug Generator

](https://webaloha.co/tools/slug-generator/)[![Markdown to HTML Converter Tool Online](https://webaloha.co/_astro/tool-markdown-to-html.BhNXTr_e_Z1VoeFe.webp?dpl=dpl_H1MtSCmk524EGpEs7Etp4HWKr3Ti)

Markdown to HTML Converter

](https://webaloha.co/tools/markdown-to-html-converter/)

## Regex Tester: FAQ

Which regular-expression engine does this tester use?

It uses the JavaScript RegExp engine in your current browser. The available syntax therefore follows that browser's ECMAScript support, which can differ from PCRE, Python, .NET, RE2, or an older JavaScript runtime.

How do the g, i, m, s, and u controls affect the preview?

The g flag shows all matches; without it the tool stops after the first. The i flag ignores case, m changes how line anchors work, s lets dot match line breaks, and u enables Unicode-aware pattern parsing. You can also type flags directly, and invalid combinations produce an error.

Why are capture groups shown only once?

The group panel displays numbered and named groups from the first match so the layout stays readable. The highlight and match count still cover every match when g is enabled. Inspect later groups in your application if captures vary by match.

How does the replacement preview handle group references?

The preview uses JavaScript String.replace. Use $1 and $2 for numbered groups, $<name> for a named group, and $& for the complete match. Without the g flag, only the first match is replaced.

Why does the tool say preview skipped?

The live preview stops when the pattern exceeds 500 characters, the test text exceeds 20,000 characters, or a heuristic detects nested repetition or repeated wildcards that may cause catastrophic backtracking. Simplify the pattern or test a smaller representative sample.

What does an invalid result mean?

The browser could not construct a RegExp from the pattern and flags. Read the displayed engine message, then check unbalanced brackets, unsupported syntax, incomplete escapes, or duplicate flags. The tool clears groups and replacement output until the pattern compiles.

How are empty-string matches handled?

Patterns such as ^, $, or a zero-width lookaround can match a position without consuming text. The preview manually advances after a zero-length match to avoid an infinite loop, so test boundary-heavy patterns again in the exact runtime where you will deploy them.

Are my pattern, sample text, and replacement uploaded?

No. Pattern compilation, matching, highlighting, and replacement all run in your browser. The entered pattern and text are not sent to a Web Aloha API or saved by this tool.

## Need Custom Tools or Automation?

From data cleanup to bespoke web apps, we build fast, reliable tooling that saves your team hours.

[Get a Free Website Audit 💪](https://webaloha.co/free-website-audit/)
