Regex Explainer
Plain-English token-by-token breakdown of any regex pattern.
Test your regular expressions with real-time match highlighting and capture group inspection. Toggle flags, paste your test string, and see every match the moment you type.
\d+ to match numbers).Regular expressions (regex or regexp) are sequences of characters that define a search pattern. They are supported in virtually every programming language and text editor, and they power features like find-and-replace, input validation, log parsing and data extraction. A regex pattern can match literal characters, character classes (such as digits or whitespace), repetitions, alternations and positional anchors, giving you precise control over what text you want to find.
Flags modify how the regex engine processes a pattern. The global flag (g) tells the engine to find every match in the string rather than stopping after the first. The case-insensitive flag (i) treats uppercase and lowercase letters as equivalent. The multiline flag (m) changes the meaning of ^ and $ so they match the start and end of each line instead of the entire string. The dotAll flag (s) allows the dot metacharacter to match newline characters, which it skips by default.
Common use cases include validating email addresses and phone numbers in form inputs, extracting structured data from semi-structured text like log files and CSV exports, performing bulk search-and-replace operations in codebases, and writing URL routing rules in web frameworks. Learning regex is one of the highest-leverage skills a developer can invest in because it applies across languages, tools and platforms.
^ and $ match line boundaries rather than string boundaries; and s (dotAll) lets . match newline characters. You can combine them freely depending on your requirements.., (, ) or [ that have special meaning in regex syntax, using anchors like ^ and $ without the multiline flag on multi-line text, or a simple typo. Try reducing your pattern to a minimal version and building it back up incrementally to isolate the problem..* is greedy and matches as many characters as possible while still allowing the overall pattern to succeed. .*? is lazy (reluctant) and matches as few characters as possible. For instance, against the text <b>hello</b>, the pattern <.*> greedily matches the entire string, while <.*?> lazily matches only <b>. Use lazy quantifiers when you want the shortest match between delimiters.g (global) to find all matches, i (case-insensitive) to ignore letter casing, m (multiline) to make anchors match line boundaries, and s (dotAll) to let the dot match newline characters. Flags can be combined to fine-tune matching behavior for your specific use case.(\d{3})-(\d{4}) applied to "555-1234" captures "555" in group 1 and "1234" in group 2. Capture groups are useful for extracting substrings, performing replacements, and validating structured input like dates and phone numbers.? after a quantifier, consumes as few characters as possible. For example, given <b>hello</b>, the greedy pattern <.*> matches the entire string, while the lazy pattern <.*?> matches only <b>. Choose lazy matching when you need the shortest possible match between delimiters.