Match Moderation Patterns Supporting Dot and Star Wildcards
Last updated: November 29, 2026
Quick Overview
Implement full-string matching for patterns where '.' matches any single character and '*' means zero or more of the preceding element. Return whether the pattern matches the entire input string.
Meta
November 29, 20260
0
0 solved
Implement full-string matching for patterns where '.' matches any single character and '*' means zero or more of the preceding element. Return whether the pattern matches the entire input string.
Pattern matching underpins content filters on Meta platforms, and this regular expression subset is a known Meta onsite Hard. Interviewers want a clear DP recurrence, especially the two choices a star offers, and correct handling of empty strings.
What the Interviewer Expects
- Defines a clear DP state over suffixes or prefixes
- Handles '*' as zero occurrences or one more occurrence
- Initializes base cases for empty string versus patterns like a*b*
- Explains why greedy matching fails
- Gives O(mn) time and discusses O(n) space
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Add '+' for one or more occurrences.
- Support glob-style '?' and '*' (match any sequence) instead.
- How do production regex engines avoid exponential blowup?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
s has lowercase letters, p has lowercase letters, '.' and ''. Every '' follows a valid character. Match must cover all of s. Lengths up to 1,000....
High-Level Design
Let dp[i][j] mean s[i:] matches p[j:]. The base case dp[m][n] is true. Compute from the end. first is whether s[i] exists and equals p[j] or p[j] is '.'. If p[j+1] is '*', either skip the pair (...