LeetCode 10, Hard. Topics: String, Dynamic Programming, Recursion. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 17 parametrized pytest cases, and a playground notebook:
Problem
Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where:
'.' Matches any single character.
'*' Matches zero or more of the preceding element.
Return a boolean indicating whether the matching covers the entire input string (not partial).
Examples
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.
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
NeetCode 150, NeetCode 250, NeetCode All. Last modified on September 7, 2026