Regex Tester
Test JavaScript regular expressions against text.
[]
Test JavaScript regular expressions against text.
[]
Regular expressions are easiest to get right by trying them on real text. Type a pattern in the first box, paste sample text in the second, and the matches appear below straight away as a JSON array. Edit either box and the list refreshes, so you can tighten a pattern one character at a time.
The pattern is compiled with the same engine your browser uses for JavaScript, so what works here will behave the same in front-end code and in Node. The global flag is always on, which means you see every non-overlapping match in the text rather than just the first. The box starts with a simple email-like pattern so you can see the format of the results right away.
This is a focused tester. It lists the full matched text only. It does not highlight positions, show capture groups, or let you add flags such as case-insensitive or multiline, so it is best for confirming what a pattern finds and for catching syntax mistakes.
Before adding a pattern to a form, paste a set of valid and invalid sample values and check which ones come back as matches. It is a quick way to see whether the pattern is too loose or too strict.
Paste a block of log lines and try a pattern for request IDs, timestamps, or error codes. Seeing the list of matches tells you whether the pattern picks up everything and nothing extra.
Before running a bulk replacement in an editor or script, test the search pattern here against a sample. Catching a greedy match now is easier than undoing a change across a whole project.
If your code throws an error for a pattern, paste it in. An invalid expression shows the engine's error message, often naming the unterminated group or bad escape that needs fixing.
The expression and sample text are evaluated in your browser. Nothing you enter is sent to a server by this tool.
JavaScript, using the browser's built-in regular expression engine. Features like lookbehind and named groups depend on your browser version. Patterns written for other flavors, such as PCRE or Python, may behave differently, especially with inline modifiers, possessive quantifiers, and some character class shortcuts.
The tester runs a global match, which returns each full match as a string and drops group details. To inspect groups, use the matchAll method in your own code or a testing tool that lists them. This page is for checking what a pattern finds.
There is no flag field here, so write both cases into the pattern, for example [Hh]ello, to test the logic. In your real code, add the i flag after the closing slash or pass it as the second argument to the RegExp constructor.
An empty array means the pattern is valid but found no match in the text. Check for escaping mistakes, such as a single backslash that should be doubled in a string, extra spaces, and anchors like ^ and $ that limit matches to the whole text.
The pattern could not be compiled. Common causes are an unclosed parenthesis or bracket, a quantifier with nothing before it, or an invalid escape. The message comes straight from the engine, so read it for the specific problem and fix that part first.
Yes, in rare cases. Nested quantifiers such as (a+)+ on long, non-matching input can cause catastrophic backtracking, where the engine tries an enormous number of paths. If the page hangs, close the tab, then simplify the pattern before testing again.