Regex Tester & Debugger
Test JavaScript regular expressions online with match highlighting, capture groups, match positions and replacement preview.
Test and debug JavaScript regular expressions
Test, inspect and debug regular expressions
Your pattern and test text are processed in your browser. Nothing is sent to iToolsEra for regex matching.
/slashes/. JavaScript RegExp syntax is used.Run a regex to see highlighted matches.
Match Details
Replacement Preview
Preview what JavaScript's replace operation would produce. Your original test text is never changed.
Enter replacement text and preview the result.
What Is a Regular Expression?
A regular expression, often called a regex, is a pattern used to find, match, extract or replace text that follows specific rules. Developers use regular expressions to locate identifiers, extract values, inspect text formats and replace repeated patterns.
This online JavaScript regex tester lets you test a pattern against sample text and inspect highlighted matches, match positions and capture groups. A regex that recognizes a particular text shape is not automatically a complete validator for the underlying data; for example, a date-shaped match does not prove that the date exists on a calendar.
How to Use the Regex Tester
- Enter a JavaScript regular-expression pattern in the pattern field.
- Select the flags you need, such as
gfor all non-overlapping matches orifor case-insensitive matching. - Enter or paste representative text into the test area.
- Run the test and inspect highlighted matches, positions and captured groups.
- If the pattern is rejected, review the syntax and the error feedback.
- Enter replacement text and review the replacement preview when testing find-and-replace behavior.
Start with a small sample, then test additional cases such as empty input, unexpected characters and multiline text.
Regex Syntax Reference
| Syntax | Meaning | Example |
|---|---|---|
. | Any character except a line terminator by default | a.c |
\d | Digit | \d+ |
\w | Word character | \w+ |
\s | Whitespace | \s+ |
^ | Start anchor; line-aware with m | ^Hello |
$ | End anchor; line-aware with m | world$ |
* | Zero or more repetitions | a* |
+ | One or more repetitions | a+ |
? | Optional quantifier or lazy modifier, depending on context | colou?r |
{n} | Exactly n repetitions | \d{4} |
[...] | Character class | [abc] |
(...) | Capturing group | (\d+) |
(?:...) | Non-capturing group | (?:cat|dog) |
| | Alternation | cat|dog |
Regex syntax can vary by engine. These examples use JavaScript regular-expression syntax.
JavaScript Regex Flags
| Flag | Purpose |
|---|---|
g | Find all non-overlapping matches rather than stopping after the first. |
i | Ignore case differences. |
m | Make ^ and $ work at line boundaries in multiline input. |
s | Allow the dot to match line terminators. |
u | Enable Unicode-aware regular-expression behavior. |
y | Require matching at the current regular-expression position. |
The g and y flags have different matching behavior and are not interchangeable.
Common Regex Examples
These examples are starting points, not universal validators. Real-world data formats can require additional rules.
- Find numbers:
\d+ - Find date-shaped text:
\b\d{4}-\d{2}-\d{2}\b - Find repeated whitespace:
\s+ - Find hashtags:
#[A-Za-z0-9_]+ - Capture two words:
^(\w+)\s+(\w+)$
The date example matches a YYYY-MM-DD-shaped string but does not verify calendar validity.
Understanding Capture Groups
Parentheses create capturing groups in JavaScript regular expressions. For example, (\d{4})-(\d{2})-(\d{2}) applied to 2026-10-12 captures the year, month and day separately. The full match contains the complete date, while each numbered group contains one part.
Use (?:...) when you need grouping behavior without creating a numbered capture. Inspecting the captured values can help explain why a pattern extracts an unexpected portion of the input.
Debugging Common Regex Problems
No matches: Check spelling, escaping, anchors, whitespace and case sensitivity. A valid pattern can return zero matches for a particular sample.
Only one match: Enable the g flag when you want all non-overlapping matches.
Dot misses line breaks: JavaScript does not make . match line terminators by default; consider the s flag.
Anchors behave unexpectedly: Check whether the m flag is appropriate for line-by-line matching.
Invalid pattern: Check unmatched brackets or parentheses, quantifiers and escape sequences.
Pattern works elsewhere but not here: Regex engines differ. This tool uses JavaScript RegExp, not a PHP/PCRE, Python or .NET interpreter.
Regex Replacement Preview
The replacement preview uses JavaScript string-replacement behavior. Replacement strings can reference captured groups with tokens such as $1 and $2. Without the g flag, a standard replacement generally changes only the first match; with g, it can replace all matching occurrences.
The preview is non-destructive: it shows the proposed result without overwriting the original test text. Review the output before using it elsewhere.
JavaScript Regex vs Other Regex Engines
Regular-expression syntax and supported features vary between languages and engines. This tool uses the browser's JavaScript RegExp implementation. A pattern copied from PHP/PCRE, Python or .NET may require changes before it behaves the same way in JavaScript.
When debugging a pattern for a specific application, test it in the same regex flavor used by that application before relying on the result.
Regex Performance and Safety
Some regular expressions can perform excessive backtracking on particular inputs. This tool runs regex execution inside a browser Web Worker and uses a timeout to stop tests that run too long. Input and match limits also help protect browser responsiveness.
If a test times out, try a smaller sample, simplify nested quantifiers and reduce ambiguous alternatives. A successful short test does not guarantee efficient behavior for every possible input.
Are My Regex and Test Data Uploaded?
Regex compilation, matching and replacement preview are performed in your browser. The tool does not send the regex pattern or test string to iToolsEra for matching. Avoid pasting passwords, private keys or other sensitive information into online tools unless your security requirements allow it.
Frequently Asked Questions
Related Tools
Explore more useful tools.