Regular Expression Matching
Given an input string s and a pattern p, return true if p matches the entire string s. The pattern supports '.', which matches any single character, and '*', which matches zero or more of the character immediately preceding it. The match must cover the whole string, not a partial prefix.
Open official problem prompt ↗We want to know whether the pattern, with '.' and '*', can be stretched to cover the whole input string exactly.
Like checking a filename against a shell-style rule where 'a*' can expand to any number of a's, and testing every legal expansion at once.
- Input
- s = "aa", p = "a*"
- Output
- true
- Why
- 'a*' means zero or more 'a', which can match the two a's in "aa".
1 <= s.length <= 201 <= p.length <= 20s contains only lowercase English lettersp contains lowercase letters, '.', and '*'Each '*' is preceded by a valid character or '.'