Regex Tester
Test JavaScript regular expressions in your browser. Toggle g, i, m, s, u, and y. Inspect capture groups. Preview String.replace with $1, $&, $`, and $'.
- Free, no sign-up
- REST + MCP
- Updated
- Reviewed by Olgun Ozoktas
JavaScript String.replace patterns: $1, $&, $`, $', and $$.
How to Test Regular Expressions Online
-
Enter your regex pattern
Type or paste your regular expression into the pattern field. The tool accepts any valid JavaScript regex syntax including character classes, quantifiers, groups, and lookaround assertions. -
Set JavaScript regex flags
Toggle g (all matches), i (ignore case), m (^ and $ at line ends), s (dot matches newline), u (Unicode), and y (sticky at lastIndex). -
Add a test string
Paste text to test. You can add more than one string. Matches highlight as you type. -
Preview replace with $1
Enter a replacement such as $1. The preview uses JavaScript String.replace. Load sample uses pattern (\w+), replace $1, and the string hello world.
Common Use Cases
Email Validation
Data Extraction
Search and Replace
Log Parsing
Why use our Regex Tester?
This page tests JavaScript regular expressions in your browser. Matches highlight as you type. Capture groups show as $1, $2, and so on. The Replace field runs JavaScript String.replace, so $1, $&, $`, and $' work the same as in your code.
Supported flags are g, i, m, s, u, and y. The u flag enables Unicode property escapes. The y flag is sticky and matches only at lastIndex. Other languages share much of this syntax, but this tool does not emulate Python, PCRE, or Go engines.
Use the sample path to confirm replace: pattern (\w+), replace $1, test string hello world. Pair this tool with the Glob Pattern Tester for file paths, or the Diff Checker to compare text after a replace. Processing stays in this browser. The page does not upload your test strings.
How it compares
This tester uses the JavaScript regex engine in your browser. Your pattern and test strings stay in this tab. The page does not upload them. Other sites may offer extra engines or a pattern library. This page focuses on JavaScript match, flags, and String.replace with $1.
Regex Tips & Best Practices
- Use character classes like \d, \w, and \s instead of broad patterns like.* to make your regex faster and more precise. Specific classes reduce backtracking and clearly communicate intent to other developers.
- Anchor your patterns with ^ and $ when you need to match an entire string. Without anchors, your regex will match substrings, which can lead to false positives in validation scenarios.
- Avoid nested quantifiers such as (a+)+ or (.*?)* that can cause catastrophic backtracking. If your regex takes noticeably long on certain inputs, nested repetition is usually the culprit.
- Use non-capturing groups (?:..) when you need grouping for alternation or quantifiers but do not need to extract the matched text. This improves performance and keeps your capture group numbering clean.
- Test your regex against edge cases, not just the happy path. Empty strings, very long inputs, special characters, and unicode text can all reveal problems that normal test data hides.