You are given a text string and a pattern string. The pattern may contain two special characters: a dot '.' that stands for any single character, and a star '*' that lets the character immediately before it repeat zero or more times. Decide whether the pattern is able to describe the text from beginning to end.
Matching must cover the whole text, not just a prefix. A '*' is never the first symbol of the pattern and always follows an ordinary character or a dot, so every star has something it can repeat.
Example 1
Input: s = "aa", p = "a*"
Output: true
The star lets "a" appear twice, which reproduces "aa" exactly.
Example 2
Input: s = "abc", p = ".*d"
Output: false
".*" can consume "abc", but the trailing "d" then has nothing left to match, so the whole pattern fails.
Constraints
1 ≤ s.length ≤ 201 ≤ p.length ≤ 30s contains only lowercase English lettersp contains lowercase letters, '.', and '*', where every '*' follows a valid characterSee the step-by-step animation, the intuition, and clean code in every language — free, no credit card.
FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI