By JW Tool Box
How to Test Regex Online: A JavaScript Starter Walkthrough
Last updated
A first-test walkthrough with an invoice example, supported flags and positive and negative cases.
Why trust this guide
- Written by JW Tool Box around the actual workflow or linked tool on this page.
- Updated when browser behavior, file handling, or platform dimensions change in ways that affect the steps.
- Focused on practical settings, safe defaults, and real tradeoffs instead of generic filler.
To test a JavaScript regular expression online, open the Regex Tester, enter the pattern without / delimiters, and paste a short sample. The page highlights matches and lists their starting indexes and numbered capture groups. Use invented text while learning.
Your first test: find an invoice number
- Enter
INV-(\d{4})-(\d{3})in the pattern field. - Leave the default
gandiflags enabled. - Enter
Invoice: INV-2026-001in the text field. - Check the match
INV-2026-001, index9, group 12026and group 2001. - Replace the text with
Invoice: INV-26-001. It should produce no match.
The two samples test different outcomes. Matching one example alone does not establish that a pattern is suitable for your application.
Use a starter pattern, then change one thing
The current starter buttons cover email-like text, US phone numbers, IPv4 addresses, hex colors and invoice identifiers. There is no URL starter button. Selecting a starter replaces the pattern; the sample text and flags remain available to edit.
Try the email starter with Contact hello@example.com or admin@test.co.uk. You should see two matches. Then test Contact invalid@ as a negative case. The starter finds familiar email-like strings; it is not a complete email validator or an address-deliverability check.
A short syntax reference
| Syntax | Meaning | Example |
|---|---|---|
\d |
ASCII digit | \d{3} matches 123 |
\s |
Whitespace | a\s+b matches a b |
[abc] |
One listed character | [ab] matches a or b |
+ |
One or more | a+ matches aaa |
{n} |
Exactly n repetitions | \d{4} matches 2026 |
(…) |
Capture a group | (INV) captures INV |
^ and $ |
Start and end assertions | ^INV-\d{4}-\d{3}$ checks the whole line in a simple sample |
The UI provides g, i, m, s and u toggles. Read the debugger guide for Unicode, browser compatibility and the current all-match collection behavior. The tool does not currently support the v flag.
Why a pattern can appear correct but still be wrong
A hex-color search may find #123 inside #12345G. A date-shaped string may contain a nonexistent day. A phone-shaped match does not confirm a working phone number. Define whether you want to extract part of a longer string or validate an entire field, then test both valid and invalid inputs.
For a production rule, include empty text, extra characters, line breaks and boundary lengths. Test it in the actual application runtime too: this page uses JavaScript, not Python or PCRE. The MDN regex guide explains the syntax and flags.
Practical safety and privacy limits
Evaluation happens in your browser. Analytics and ads still operate separately under the Privacy Policy. Use synthetic samples without passwords, API keys or personal records. Avoid long, unfamiliar patterns: matching runs on the main thread and has no execution timeout, so an expensive expression may freeze the tab.
If your test input is a JSON payload, format it with the JSON Formatter. Save your expected result separately and use the Text Diff Checker when checking a changed pattern.
About the author
JW Tool Box - Editorial and product review team
JW Tool Box publishes hands-on guides tied directly to the site's browser-based tools. Content is updated when browser behavior, platform rules, or product requirements change in ways that affect real workflows. The goal is to provide practical instructions, tested defaults, and trustworthy reference content instead of thin keyword filler.
Related guides
-
JavaScript Regex Debugger Guide: Capture Groups, Flags and Browser Limits
Use the JavaScript Regex Tester to inspect matched text, its index and numbered capture groups. This guide focuses on debugging behavior and browser limits. For your first test, use the basic regex walkthrough. Start with a small, reproducible example Enter the pattern without surrounding / characters. For an invoice identifier, use: regex
Related tools
Additional browser-based utilities that are closely related to this workflow.
-
JSON Formatter & Validator (Minify, Beautify, Fix JSON)
Pretty-print, minify, or validate JSON documents instantly.
-
Text Diff Checker (Compare, Highlight, Difference)
Highlight differences between two blocks of text in seconds.
-
Regex Tester: Test & Debug Regular Expressions Online
Test regex patterns, see matches highlighted in real time, and debug regular expressions — all in your browser.