Regex Replace Tester (Test JavaScript Regular Expressions Online)
Stop guessing if your Regex replacement logic works. This tool perfectly simulates the JavaScript String.replace() method inside the browser. Type your expression, define your capture groups, and watch the output text update instantaneously.
100% Private & Secure
This tool runs completely inside your browser using client-side WebAssembly and JS. Zero data is ever sent to our servers.
How to use this tool
- Type your target text into the 'Test String' box on the left.
- Enter your Regular Expression pattern and specific flags (like 'g' for global or 'i' for case-insensitive).
- Type your replacement logic. You can use standard string replacements or JavaScript capture group syntax (e.g., $1 or $2).
- The Result box on the right will instantly reflect the simulated output.
Example Usage
Regex: (Hello) (World) Replace: $2 $1 Text: Hello World
World Hello
Regex: \d+ Replace: [REDACTED] Text: Phone: 5551234
Phone: [REDACTED]
When to use this tool
- Debugging complex capture group swaps (e.g., reformatting dates from MM-DD-YYYY to YYYY-MM-DD).
- Validating data sanitization scripts before deploying them to a backend Node.js server.
- Testing regex boundary flags and multi-line matching behavior.
- Learning and visualizing how different regex flags (g, m, i, u) alter replacement outcomes.
Frequently Asked Questions
Which Regex engine does this tool use?
This tool runs entirely in your browser using the native ECMAScript (JavaScript) Regular Expression engine. It behaves exactly like calling .replace() in a Node.js or browser environment.
How do I reference capture groups in the replacement?
You can reference capture groups identically to JavaScript syntax using the dollar sign. $1 refers to the first captured group in parentheses, $2 refers to the second, and $& references the entire matched substring.
What does the 'g' flag do in a replacement?
The 'g' (global) flag forces the regex engine to replace every single occurrence of the pattern in the string. Without it, the engine will stop and return after making only the very first matched replacement.
Why isn't my negative lookbehind working?
Lookbehinds (e.g., (?<=a)b) are supported in modern JavaScript engines (V8, SpiderMonkey), meaning they will work in this tool on all modern browsers. However, if you are testing here but deploying to an older environment (like legacy Safari), the regex might fail in production.
Is this safe for testing sensitive strings?
Yes. All pattern matching and text parsing occurs locally in your device's memory. The test strings and regex patterns are never submitted over a network, making it completely safe for proprietary logs or PII.