Small Tools
Regex utility

Regex Replace Tester

Preview JavaScript regular expression replacements on sample text.

● This tool runs entirely in your browser. Your input is never uploaded to our servers.

Use short sample text. Complex patterns can take a long time to run.

Output
Your result will appear here…

How to use Regex Replace Tester

  1. Enter the Regular expression and the Flags; g is filled in by default.
  2. Enter the Replacement and paste the sample text.
  3. Select Replace and read the result.

Example

Input / settings:

Regular expression: user_(\d+)
Flags: g
Replacement: account-$1
Text: user_123, user_456

Output:

account-123, account-456

$1 inserts the first capture group, so each number is kept and the prefix changes.

When to use

Overview

Regex Replace Tester runs JavaScript's String.replace with the pattern, flags and replacement you enter on sample text of up to 5,000 characters, with patterns of up to 250 characters. It shows only the replaced text. The replacement is a string that can use JavaScript's special tokens such as $1 and $&; it is not a function, and the engine is your browser's, not PCRE or Python.

Supported input

pattern, replacement, and text

Output details

replaced text

Common mistakes

Practical tips

Privacy and security

This tool runs entirely in your browser. Your input is never uploaded to our servers. Replacement runs locally with your browser's regular expression engine and nothing is uploaded. Be careful with patterns copied from untrusted sources: nested repetition can make the tab unresponsive, as the OWASP ReDoS page explains.

References

Frequently asked questions

Which flags does Regex Replace Tester accept?

Any flags your browser's RegExp accepts, such as g, i, m, s, u and y. A repeated flag like gg or an unknown one like z returns an error.

What are the size limits?

The pattern can have up to 250 characters and the sample text up to 5,000. Longer input is rejected with a message.

Can the replacement be a function?

No. The replacement is plain text with the special tokens $1, $&, $<name>, $$, $` and $'.

Related tools