SanWebCorner · Developer Tools
Regex Tester & Replacement Preview
Test JavaScript regular expressions against sample text and preview replacements locally in your browser. A separate worker keeps evaluation off the page’s main thread and stops a run after 1.5 seconds.
How to test a regular expression
- Enter a pattern without enclosing / characters and choose JavaScript flags.
- Paste test text or load the sample.
- Select Test regex for match details, or Preview replacement for transformed text.
- Copy or download the result. Cancel stops an active evaluation; changing any input also cancels it.
Flags and match behavior
Use g for all matches and i for case-insensitive matching. Without g, only the first match or replacement is returned. Other flags depend on your browser’s JavaScript RegExp support; invalid or duplicate flags produce an error. This tool uses JavaScript syntax, not PCRE, Python or a database regex dialect.
Results show the matched text, its UTF-16 start index, numbered captures and any named groups. Empty global matches advance to avoid an infinite loop; Unicode-aware modes advance by code point. See the MDN RegExp reference.
Replacement example
Pattern: ([a-z]+)@example\.com
Flags: gi
Text: alice@example.com and bob@example.com
Replacement: $1@sample.test
Result: alice@sample.test and bob@sample.test
Supported replacement tokens follow JavaScript string replacement: $$ for a literal dollar sign, $& for the match, numbered captures, named captures, and the prefix/suffix tokens. Preview does not edit your original input or execute a replacement as code.
Timeouts and limits
A complex regular expression can take much longer than expected. Evaluation runs in a disposable Web Worker with a 1.5-second timeout and a Cancel button. If workers cannot run, the tool reports an error and does not fall back to evaluation on the main thread. MDN documents that Worker.terminate() stops a worker immediately.
Limits: 2,000 characters each for pattern and replacement, 50,000 characters of test text, 1,000 matches and 200,000 output characters. Match listings may be truncated with a notice. Replacement previews that exceed the limits are rejected without keeping partial output. Limits count UTF-16 code units. A timeout is a practical guard, not a proof that an expression is efficient in your application.
Privacy and frequently asked questions
Does the regex tool send text to a server?
The component evaluates input locally in the browser’s worker and keeps no input history in browser storage. Normal website advertising and analytics still run. Use an offline environment for data that must not be entered into a website.
Why is only one match shown?
Add the g flag for global matching. Without it, JavaScript uses only the first match.
Why was my run stopped?
Try less text or simplify a pattern with nested quantifiers or ambiguous alternatives. The tool cancels long evaluations rather than waiting indefinitely.