Test Regular Expressions Interactively
What It Is
A regular expression (regex) is a sequence of characters that defines a search pattern. It is used for pattern matching, search-and-replace, and input validation in text. Common uses include email validation, log parsing, URL rewriting, and code refactoring. This interactive tester lets you type a pattern, provide sample text, and immediately see which parts match in real time.
How It Works
The regex engine compiles your pattern into a finite-state machine that walks through the input text character by character. Anchors (^, $) assert positions, quantifiers (*, +, ?, {n,m}) control repetition, character sets ([abc] or \d, \w, \s) match specific groups of characters, and grouping constructs ((...), lookaheads, lookbehinds) create sub-expressions. The built-in tree explainer parses your regex into a visual hierarchy so you can inspect each token and understand its role in the full pattern.
Worked Example
To validate an email address, enter the pattern ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ with the "gm" flags.
Common Mistakes
Forgetting to escape the dot (\.) when you need a literal period instead of any-character wildcard is the most common regex bug. Not anchoring patterns with ^ and $ when validating entire strings causes partial matches to pass. Overusing greedy quantifiers (*, +) without considering backtracking can cause catastrophic backtracking and freeze your application. Always test your pattern against edge cases empty strings, very long inputs, and strings with special characters before deploying.
Frequently Asked Questions
Q:What can I test with this regex tool?
You can test any JavaScript-compatible regular expression pattern against your input text. The tool shows matches, highlight them in the text, and provides a structural tree view explaining each token in plain English.
Q:How do I use regex flags like global or case-insensitive?
Enter flags in the Flags input field (e.g., "gi" for global + case-insensitive, "gm" for global + multiline). The tool supports all JavaScript regex flags: g, i, m, s, u, y. Click "Try it" on cheat sheet patterns to see working examples.
Q:What is the Regex Tree Explainer for?
The tree view breaks down your regex into individual nodes (anchors, quantifiers, character sets, groups). This helps you understand complex patterns, debug why matches are not working, and learn regex syntax by seeing the parsed structure.
Q:Why does my regex match differently in JavaScript vs other languages?
JavaScript regex lacks some features like lookbehind (added in ES2018, now supported), possessive quantifiers, and the \x flag (extended mode). If your pattern uses these, it may fail silently or behave unexpectedly. This tool uses the JavaScript RegExp engine, so test patterns you intend to use in Node.js or browser code.
Q:How do I handle matching across multiple lines?
Use the multiline flag "m" to make ^ and $ match at line boundaries instead of string boundaries. Use the dotAll flag "s" to make the dot (.) match newline characters. Combine them as "gms" for cross-line matching with global search.