Regex Engine
Test regular expressions with live match highlighting
Matches (2)
Highlighted View
Interview Questions
Q1: How would you match a valid email address using regex?
A common pattern is [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}. For RFC 5322 compliance, the pattern is significantly more complex, but this covers most practical cases. Note that regex alone cannot validate all edge cases (e.g., nested comments).
Q2: What is the difference between greedy and lazy quantifiers?
Greedy quantifiers (default: *, +, {n,m}) match as much as possible while still allowing the overall pattern to match. Lazy quantifiers (*?, +?, {n,m}?) match as little as possible. For example, on 'aaab', /a+b/ matches 'aaab' greedily, but /a+?b/ still needs the 'b', so it also matches 'aaab' but tries fewer 'a's first.
Q3: Explain Kleene's theorem and its significance.
Kleene's theorem states that a language is regular if and only if it can be described by a regular expression. This bridges the gap between algebraic descriptions (regex) and machine-based recognition (finite automata). It implies that we can always convert between regex and DFA/NFA, which is the foundation of tools like grep, lex, and pattern matching in programming languages.