Regex Tester & Debugger — Test JavaScript Regular Expressions Live
Test and debug JavaScript regular expressions in real-time. Enter a pattern, flags, and test string to see match count, matched substrings, and whether a.
The formula
/pattern/flags → RegExp.prototype.test() → boolean match result
- Pattern
- Regex Pattern
- Flags
- Regex Flags
- Test String
- Input Text
- Match
- Matched Substring
- Quantifier
- Repetition Operator
How Regex Tester Works
/pattern/flags → RegExp.prototype.test() → boolean match result
Regular expressions (regex) are patterns used to match character combinations in strings. A regex pattern is compiled into a finite state machine that scans the input string character by character, attempting to find matches according to the pattern rules. Flags modify matching behavior: g (global) finds all matches, i (case-insensitive) ignores case, and m (multiline) treats ^ and $ as line boundaries.
- Pattern
- Regex Pattern — The regular expression pattern string defining the matching rules using special syntax like character classes, quantifiers, and groups.
- Flags
- Regex Flags — Modifiers that change matching behavior: g for global (find all matches), i for case-insensitive, m for multiline (^/$ match line boundaries).
- Test String
- Input Text — The string of text that the regex pattern is applied to for finding matches.
- Match
- Matched Substring — A portion of the test string that satisfies the regex pattern. Multiple matches can be found with the global (g) flag.
- Quantifier
- Repetition Operator — Symbols like *, +, ?, and {n,m} that specify how many times a character or group should appear in the match.
How to Use
- Enter your regex pattern in the Pattern field (without delimiters).
- Select optional flags: g for global matching, i for case-insensitive, m for multiline.
- Enter or paste a test string to search against in the Test String field.
- View match count, matched substrings, and whether a match was found.
Quick Reference
| . | Any character except newline |
| * / + / ? | Zero-or-more / One-or-more / Zero-or-one |
| \d / \w / \s | Digit / Word char / Whitespace |
| ^ / $ | Start of string / End of string |
| [abc] / [^abc] | Character class / Negated class |
| (group) | Capture group (backreference via \1) |
Common Uses
- •Validating input formats like email addresses, phone numbers, and URLs.
- •Searching and replacing text patterns in code editors and data pipelines.
- •Extracting specific data from unstructured text logs and documents.
- •Parsing and tokenizing strings in compilers, interpreters, and data processors.
Understanding the Result
Regular expressions are a powerful tool for pattern matching and text manipulation that exist in virtually every programming language. The regex engine compiles a pattern into an internal finite automaton and processes the input string left to right. Patterns can include literal characters, metacharacters with special meaning (., *, +, ?, [], (), {}, ^, $), character classes (\d, \w, \s), and anchors (^ for start, $ for end). The global flag (g) is critical for finding all matches rather than just the first one. Case-insensitive flag (i) matches both uppercase and lowercase letters. Multiline flag (m) changes the behavior of ^ and $ anchors to match at every line boundary rather than just the string boundaries. Understanding greedy vs. lazy matching is also important: by default quantifiers are greedy (match as much as possible), adding ? makes them lazy (match as little as possible). Care must be taken with complex patterns as catastrophic backtracking can cause performance issues on certain inputs.
Worked Examples
Testing an Email Extraction Pattern
pattern = [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} · flags = g · testString = Contact us at support@example.com or sales@company.co.uk for inquiries. Invalid: not-an-email@
Match Found: Yes — 2 matches (support@example.com, sales@company.co.uk)
This pattern matches 2 email addresses: "support@example.com" and "sales@company.co.uk". The character class [a-zA-Z0-9._%+-]+ matches the local part (before @), followed by @, then the domain with at least one dot and a TLD of 2+ characters. The "not-an-email@" fragment does not match because it lacks a TLD after the @. This pattern handles common email formats but would reject valid emails with quoted local parts or IP-address domains.
Extracting All Numbers from a Log File
pattern = \d+\.?\d* · flags = g · testString = Temperature: 72.5 F | Humidity: 45% | Wind: 12.3 mph | Pressure: 1013.25 hPa | UV Index: 6
Match Found: Yes — 5 matches (72.5, 45, 12.3, 1013.25, 6)
The pattern \d+\.?\d* matches one or more digits, optionally followed by a decimal point and more digits. Applied to this sensor log, it extracts 5 matches: "72.5", "45", "12.3", "1013.25", "6". Notice that "45" and "6" are matched as integers because the decimal portion \d* is optional (zero or more). The percent sign and units are not matched because they are not digits. This pattern is useful for parsing sensor data, financial logs, or any text containing mixed measurements.
Frequently Asked Questions
- What is the difference between greedy and lazy matching?
- Greedy quantifiers (*, +) match as much text as possible while still allowing the overall pattern to match. Lazy quantifiers (*?, +?) match as little as possible. For example, on the string "<div><p>text</p></div>", the pattern "<.+>" greedily matches the entire string, while "<.+?>" matches only "<div>".
- Why does my regex cause the browser to hang?
- This is called catastrophic backtracking. It happens when a regex with nested quantifiers (like (a+)+b) is applied to a string that almost matches but fails at the end. The engine tries every possible way the quantifiers could distribute the characters, which grows exponentially. Avoid nested quantifiers and use atomic groups or possessive quantifiers where supported.
- How do I match a literal special character like "." or "*"?
- Escape the special character with a backslash. Use \. to match a literal dot, \* to match a literal asterisk, \\ to match a literal backslash, etc. Inside character classes [...], most metacharacters lose their special meaning and don't need escaping.
- What is the difference between test() and exec()?
- test() returns a boolean (true/false) indicating whether a match was found. exec() returns an array with the matched text, capture groups, and properties for the position. Use test() for simple validation and exec() when you need detailed match information or capture groups.
- How do I validate common formats like email, URL, or phone number with regex?
- Email validation: a basic pattern is /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}/ but the full RFC 5322 email spec requires a much more complex regex (hundreds of characters). For practical use, a simple pattern plus a verification email is often more reliable than a perfect regex. URL validation: /https?://(www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}.[a-zA-Z0-9()]{1,6}([-a-zA-Z0-9()@:%_+.~#?&//=]*)/. Phone (US): /^(?d{3})?[-.s]?d{3}[-.s]?d{4}$/ handles (123) 456-7890, 123-456-7890, and 1234567890. Remember that regex validation is a first line of defense — always sanitize and validate server-side as well.
Pro Tips
- →Use non-capturing groups (?: ... ) instead of regular parentheses when you do not need to extract the group. They are faster and avoid cluttering your match results with unwanted capture groups.
- →The g flag changes exec() behavior: with g, each call advances the lastIndex pointer and returns the next match. Without g, exec() always returns the first match. Always reset lastIndex to 0 or use a fresh regex when switching between test strings with the same pattern.
- →For password validation, use multiple separate regex tests rather than one monster regex. Test for length, uppercase, lowercase, digits, and special characters separately — this produces clearer error messages and is easier to maintain.
- →When building regex patterns, test them incrementally. Start with the simplest case, verify it works, then add complexity. Our tool shows match count and first 10 matches — use these to confirm your pattern behaves as expected before deploying it in code.
- →Escape user-provided strings used in dynamic regex patterns to prevent regex injection and catastrophic backtracking. Use a function to escape special characters: function escapeRegex(s) { return s.replace(/[.*+?^${}()|[]\]/g, '\\$&'); }. Never directly interpolate user input into a regex pattern.
Limitations to Know
- •This regex tester uses the JavaScript RegExp engine (ECMAScript specification). Regex patterns that work here may behave differently in other regex flavors: Python's re module, PCRE (PHP/Perl), .NET, Java, and POSIX regex each have their own feature sets and syntax variations.
- •Features NOT supported by JavaScript's engine include: lookbehind assertions (supported in ES2018+ but with limitations — must be fixed-width), possessive quantifiers (++, *+, ?+), atomic groups (?> ... ), recursive patterns, and named capture groups with the (?P<name>... ) syntax.
- •Unicode property escapes (\p{L}, \p{N}) require the u flag in JavaScript and are not supported in this tool if the u flag cannot be combined with the selected flags.
- •The regex engine can hang (catastrophic backtracking) on certain pathological patterns with nested quantifiers — our tool does not implement a timeout or regex interrupt mechanism.
Cite this calculator
TheCalcUniverse. "Regex Tester & Debugger — Test JavaScript Regular Expressions Live." TheCalcUniverse, 2026, https://thecalcuniverse.com/devtools/regex-tester/. Accessed July 24, 2026.
Embed this calculator on your site
You may also like
-
Case Converter
Convert text between 9 case formats: camelCase, PascalCase, snake_case, kebab-case, dot.case, Title Case, Star…
-
Code Diff Checker — Compare
Compare two blocks of text or code side-by-side. See additions, deletions, and unchanged lines highlighted for…
-
JSON Formatter
Format, validate, and beautify JSON data instantly. Paste messy JSON and get clean, indented output with synta…
-
Timestamp Converter
Convert Unix timestamps to human-readable dates and vice versa. Supports seconds, milliseconds, and various da…