Problem
You get a string s and a pattern p. Return true if p matches all of s. Otherwise, return false.
The pattern can contain two special characters. The character . matches any one character. The character * matches zero or more copies of the character just before it.
Each other character in p matches only itself. The pattern must match the full string, not only a part of it.
Example 1
- Input:
- s = "aab", p = "a*b"
- Output:
- true
- Explanation:
a*matches"aa", andbmatches"b".
Example 2
- Input:
- s = "xyz", p = "x."
- Output:
- false
- Explanation:
x.matches only two characters, butshas three characters.
Example 3
- Input:
- s = "mmmq", p = ".*q"
- Output:
- true
- Explanation:
.*matches"mmm", andqmatches"q".
Constraints
- 1 <= s.length <= 20
- 1 <= p.length <= 20
- s has only lowercase English letters.
- p has only lowercase English letters, `.` and `*`.
- Each `*` in p has a letter or a `.` before it.
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 2 records
Amazon
Leetcode 10. Regular Expression Matching
Reported Jan 28, 2026 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceMicrosoft
Leetcode 10. Regular Expression Matching
Reported Mar 14, 2026 · 1 source report
STAFF
Source snapshot: Nov 12, 2026
View source