Back to DSA
Regular Expression Matching
hardImplement a pattern matcher that supports two special characters: '.' which matches any single character, and '*' which matches zero or more repetitions of the character immediately before it. The match must account for the entire input string, not just a substring.
Examples
Example 1:
Input:
s = "abbc", p = "a.*c"Output:
trueExplanation: '.' followed by '*' matches any number of any character, covering 'bb'. Then 'c' matches 'c'.
Example 2:
Input:
s = "hello", p = "he*lo"Output:
falseExplanation: 'e*' can match zero or more 'e's, giving 'hlo' or 'helo' or 'heelo' etc., but none equals 'hello'.
Hints
1234567