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 search text for characters, words or structures that follow specific rules. Developers use regular expressions for tasks such as finding identifiers, extracting values, checking text formats, replacing repeated patterns and validating input.
A regex is made from ordinary characters and special syntax such as character classes, quantifiers, anchors and groups. The exact syntax depends on the regex engine, so a pattern that works in one programming language may need changes in another.
How to Use the Regex Tester
- Enter a JavaScript regular expression without surrounding slash delimiters.
- Select the flags you need, such as
gfor global matching orifor case-insensitive matching. - Paste or type the text you want to test.
- Click Test Regex or press Ctrl/Cmd + Enter.
- Review the highlighted matches, match positions and capture groups.
- Use Replacement Preview when you want to see how JavaScript replacement text would change the result.
Regex Syntax Reference
| Syntax | Meaning | Example |
|---|---|---|
. | Any character except a newline by default | a.c |
\d | Digit | \d+ |
\w | Word character | \w+ |
\s | Whitespace | \s+ |
^ | Start of input or line depending on mode | ^Hello |
$ | End of input or line depending on mode | world$ |
* | Zero or more repetitions | a* |
+ | One or more repetitions | a+ |
? | Optional or lazy modifier depending on context | a? |
{n} | Exactly n repetitions | \d{4} |
[...] | Character class | [abc] |
(...) | Capturing group | (abc) |
(?:...) | Non-capturing group | (?:abc) |
| | Alternation | cat|dog |
JavaScript Regex Flags
| Flag | Purpose |
|---|---|
g | Find all matches instead of stopping after the first match. |
i | Match letters without treating uppercase and lowercase as different. |
m | Make ^ and $ work with individual lines in multiline text. |
s | Allow the dot to match newline characters. |
u | Enable Unicode-aware regular-expression behavior. |
y | Use sticky matching from the regex current position. |
Common Regex Examples
These examples are starting points rather than universal validators. Real-world formats can be more complicated than a short pattern suggests.
- Numbers:
\d+ - ISO date:
\b\d{4}-\d{2}-\d{2}\b - Whitespace:
\s+ - Hashtag:
#[A-Za-z0-9_]+ - Two captured words:
^(\w+)\s+(\w+)$
Understanding Capture Groups
Parentheses create capturing groups in JavaScript regular expressions. When a pattern such as (\d{4})-(\d{2})-(\d{2}) matches 2026-09-21, the full match is the complete date and the three groups contain the year, month and day. The tool displays these groups for each match so you can see exactly which parts of the pattern captured text.
Use (?:...) when you need grouping behavior but do not want a numbered capture group.
Debugging Common Regex Problems
No matches: check spelling, anchors, escaping, whitespace and case sensitivity. If the pattern should find more than one occurrence, check whether the g flag is required.
Only one match: JavaScript returns the first match when global matching is not enabled. Add the g flag when you want all matches.
Dot does not match a newline: JavaScript does not make . match line breaks by default. Try the s flag when that behavior is required.
Pattern works elsewhere but not here: regex engines differ. This tool uses JavaScript RegExp syntax and is not a PHP/PCRE, Python or .NET regex interpreter.
Regex Replacement Preview
The replacement preview uses JavaScript string replacement behavior. Replacement strings can reference capture groups with tokens such as $1 and $2. Without the g flag, a normal replacement replaces only the first match; with g, matching occurrences are replaced throughout the test string.
The preview is non-destructive: the original test text in the editor is not changed.
JavaScript Regex vs Other Regex Engines
Regular-expression features vary between languages and engines. This tool uses the browser's JavaScript RegExp implementation. A pattern copied from a PHP application, PCRE-based utility, Python program or .NET project 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 a very large amount of backtracking on certain inputs. This tool runs regex execution inside a browser Web Worker and stops an execution that exceeds its short safety timeout. Large test inputs are also limited for browser responsiveness.
If a pattern times out, simplify nested quantifiers, reduce ambiguous alternatives, or test a smaller sample before using the pattern in an application.
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. Even with browser-side processing, avoid pasting secrets, passwords, private keys or other sensitive information into online tools unless your organization's security requirements allow it.
Frequently Asked Questions
Related Tools
Explore more useful tools.