Regex Tester
Test a JavaScript regular expression against sample text and see every match it finds, with support for the global, ignore-case, and multiline flags.
Regex Tester
Calculator
Adjust values & calculateEnter your values below. Every result is computed in your browser โ no data is sent to any server.
Formula: JavaScript RegExp: new RegExp(pattern, flags)
Worked example โ 2 matches found
Formula
JavaScript RegExp: new RegExp(pattern, flags)
Tests a regular expression against a string and shows all matches. Common: \d (digit), \w (word char), . (any), * (0+), + (1+), ? (0-1).
Worked Examples
Example 1: Find phone numbers
Problem:Pattern: \d{3}-\d{4}, Text: "Call 555-1234 or 555-5678"
Solution:2 matches: 555-1234, 555-5678
Result:2 matches found
Frequently Asked Questions
What are the most common regex patterns?
Email: [\w.-]+@[\w.-]+\.\w+. Phone: \d{3}[-.]?\d{3}[-.]?\d{4}. URL: https?://[\S]+. IP: \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}.
What do the g, i, and m flags change about a match?
The g flag makes the engine keep scanning after the first hit, which is what lets matchAll collect every occurrence rather than one. The i flag folds case, so /cat/i also matches Cat. The m flag makes the ^ and $ anchors bind to line boundaries instead of only the start and end of the whole string. JavaScript also offers s so the dot matches newlines, u for full Unicode code point handling, and y for sticky matching that resumes at lastIndex.
What is the difference between a greedy and a lazy quantifier?
Quantifiers such as *, + and {2,} are greedy: they consume as much as the string allows and then hand characters back only when the rest of the pattern fails. Adding a question mark makes them lazy, so they take the minimum and expand only as needed. Against the text <a><b>, the greedy pattern <.*> matches the whole thing while the lazy <.*?> stops at <a>. The lazy form is the usual fix when a dot-star swallows more than intended.
How do capture groups differ from non-capturing groups?
Plain parentheses create a capture group, numbered left to right by the position of the opening bracket, and the captured text appears in the match array and in backreferences such as \1. Writing (?: at the start makes the group non-capturing, so it still controls grouping and alternation but adds nothing to the results. Named groups written as (?<year>\d{4}) arrived in ES2018 and expose their text through the groups object, which beats counting brackets.
What does the word boundary \b actually match?
\b is a zero-width assertion rather than a character: it matches the position where a word character, meaning the letters, digits and underscore covered by \w, sits next to a non-word character or the edge of the string. That is why \bcat\b matches the middle word of the cat sat but finds nothing inside concatenate, where c-a-t has letters on both sides. \B asserts the opposite position. Since \w is ASCII-oriented, \b behaves oddly around accented letters.
What is catastrophic backtracking and how do I avoid it?
When a pattern nests one quantifier inside another over alternatives that can match the same text, the engine may try exponentially many ways to split the input before it concedes failure. The textbook trigger is a shape like (a+)+$ tested against a long run of a followed by one other character. That is the ReDoS failure mode, and it has taken production services down. Keep alternatives mutually exclusive, anchor the pattern, avoid nesting quantifiers, and cap the length of untrusted input before matching.
When should I use lookahead instead of a capture group?
Lookaround expressions are zero-width assertions: (?=...) requires what follows, (?!...) forbids it, and the lookbehind forms (?<=...) and (?<!...) test what precedes. They check a condition without consuming characters, so the match position does not advance and the asserted text never appears in the result. Use them to match one thing only in the presence or absence of another, or to stack several independent rules into one pattern. Capture groups are for text you actually want to extract.
Why does the same global regex give different results on repeated calls?
A RegExp object carrying the g or y flag stores a lastIndex property and resumes from it on the next call. Calling test or exec twice on the same string with the same global regex therefore returns true and then false, because the second call starts after the first match and runs off the end. Reset lastIndex to 0, construct a fresh RegExp each time, or use matchAll or String.replace, which manage the iteration for you.
What is the difference between \d, \w and a custom character class?
The shorthands are abbreviations for classes: \d is [0-9], \w is [A-Za-z0-9_], \s covers spaces, tabs and line breaks, and the capitals \D, \W and \S negate each of them. A custom class lists the characters you want between square brackets, supports ranges such as [a-f], and negates with a leading caret as in [^0-9]. Because \w is ASCII-only, names carrying accents fail it; the u flag with a Unicode property escape like \p{L} is the usual remedy.
Why should a regular expression not be used to parse HTML?
Nested markup is not a regular language. A finite automaton has no counter, so no fixed pattern can track how deeply tags are stacked and pair an opening tag with its true partner; the same limit rules out balanced parentheses and JSON. A backtracking engine can fake shallow cases with backreferences, but attributes, comments, CDATA sections and unclosed tags break the illusion quickly. Use DOMParser or a real parser for structure and keep regular expressions for flat, local patterns inside text.
Background & Theory
History
Reviewed for accuracy by Daniel Agrici, Founder & Lead Developer ยท Editorial policy
Related Calculators
๐CSV to JSON Converter
Convert CSV to JSON format
๐Text Manipulator
Transform and manipulate text
๐งฎBandwidth Time Transfer Calculator
Calculate bandwidth time transfer with inputs, formulas, and instant results.
๐งฎDownload Time Calculator
Calculate download time with inputs, formulas, and instant results.
๐งฎThroughput Efficiency Calculator
Calculate throughput efficiency with inputs, formulas, and instant results.
๐งฎBase64 Encode & Decode Calculator
Calculate base64encode decode with inputs, formulas, and instant results.
๐งฎHash Checksum Calculator
Calculate hash checksum with inputs, formulas, and instant results.
๐งฎUrlpercent Encoding Calculator
Calculate urlpercent encoding with inputs, formulas, and instant results.