Test JavaScript Regex with Small Examples
Test a JavaScript pattern against small representative strings before applying it to a larger input or another regex engine.
Open the tool ↓Match the runtime you intend to use
This tester uses the browser’s JavaScript RegExp engine. A pattern from PCRE, a database, a shell or a programming language may have different escaping rules and supported syntax. Enter the pattern body without surrounding / delimiters; choose flags with the controls.
Regex Tester
Open the dedicated tester for synchronous pattern execution; keep patterns and test strings small.
Open Regex Tester →Build positive and negative examples
Try the pattern \bcat\b against cat scatter Cat. With case-insensitive matching off, the lowercase whole word should match; scatter should not. Turn on i to include the capitalised word. Add examples where you expect no match rather than testing only a string that succeeds.
- Start with a short literal and confirm the input field is being searched.
- Add boundaries, quantifiers and groups one at a time.
- Inspect match positions and captured groups.
- Recheck the pattern in the actual destination runtime.
Understand the flags in this interface
The tester offers g, i, m, s, u and y. Its match-list implementation forces global iteration internally even when the g checkbox is off. The displayed list therefore is not a demonstration of JavaScript’s single-match behavior without g.
Multiline changes anchor behavior; it does not by itself make a dot match newlines. Dot-all changes dot behavior. Sticky matching requires a match at the current search position, so it is not interchangeable with simply searching anywhere in the text. Match positions use JavaScript string indices, which are not always user-perceived character counts for Unicode text.
Keep execution bounded in practice
Patterns run synchronously in the browser. A match-count guard limits the output loop, but it is not an execution timeout for a single catastrophic backtracking attempt. Avoid long untrusted patterns and repeated ambiguous quantifiers on large text. A frozen tab is not evidence that no match exists.
Troubleshoot errors and empty results
Check missing brackets, misplaced backslashes, flags and anchoring. A displayed email-like sample is a test fixture, not a complete email-address validator. For code containing a pattern inside a JSON string, the JSON escaping layer is separate; use JSON Formatter to check that outer syntax. Use Text Diff when the real task is comparing two texts rather than matching a pattern.