Practice Regular Expression Matching
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given strings s and p, return whether p matches all of s. In the pattern, a dot (.) accepts exactly one character, while an asterisk (*) repeats the immediately preceding element zero or more times. Other letters match themselves. Matching only a substring is insufficient.
Source: Regular Expression Matching on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
s = "aa", p = "a"
Output
false
# Example 2
Input
s = "aa", p = "a*"
Output
true
# Example 3
Input
s = "ab", p = ".*"
Output
true
Constraints
1 <= s.length <= 20
1 <= p.length <= 20
s contains only lowercase English letters.
p contains only lowercase English letters, '.', and '*'.
It is guaranteed for each appearance of the character '*', there will be a previous valid character to match.
Related LeetCode Problems
Practice more problems similar to Regular Expression Matching.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.