Regex Tester
Test regular expressions against a string and see matches highlighted in real time.
About this tool
Regular expressions (regex or regexp) are a concise notation for describing patterns in text. They are built into virtually every programming language and text editor and are used for input validation, search-and-replace, data extraction, log parsing, and text transformation. The regex engine reads a pattern and applies it to a string, determining which parts of the string match and returning any captured groups.
The core syntax: literal characters match themselves. The dot . matches any single character except newline. Quantifiers control repetition: * means zero or more, + means one or more, ? means zero or one. Anchors pin the match to a position: ^ anchors to the start of the string (or line with the m flag), $ anchors to the end. Character classes in square brackets match any one character in the set: [aeiou] matches any vowel, [^0-9] matches any non-digit. Parentheses create capturing groups, and | provides alternation (either/or).
Quantifiers are greedy by default — they match as much as possible. Adding ? after a quantifier makes it non-greedy (lazy): it matches as little as possible. For example, <.+> matches everything from the first < to the last > in a string; <.+?> matches each <tag> individually. This distinction matters significantly when parsing HTML, XML, or any nested structure. Greedy quantifiers are a common source of regex bugs where the match is unexpectedly large.
Named capture groups (?<name>pattern) allow you to refer to captured text by name rather than by position, making complex regex patterns dramatically more readable. Lookaheads (?=pattern) and lookbehinds (?<=pattern) match positions without consuming characters — useful for matching a word only when followed by or preceded by a specific context. Non-capturing groups (?:pattern) group without creating a capture, which improves performance when you need grouping for quantifiers or alternation but do not need the captured text.
Regular expressions have well-known limitations. They cannot parse recursive structures (like matching balanced parentheses or validating HTML with arbitrary nesting) because finite automata cannot count. For these tasks, use a proper parser. Catastrophic backtracking is a performance risk in complex regex with nested quantifiers applied to long strings — this is the cause of ReDoS (Regular Expression Denial of Service) vulnerabilities. Always test your regex against adversarial inputs, especially if the regex will be applied to user-provided data.