Regex Lite

medium · string, dp, regex

Regex Lite ('.' and '*')

Implement a simplified regular expression matcher with two special characters:

  • . matches any single character
  • * matches zero or more of the preceding element

The match must cover the entire input string.

Function signature

func RegexMatch(s, p string) bool

Example

s = "aab"
p = "c*a*b"
output = true

Constraints

  • 0 <= len(s), len(p) <= 200

Notes

  • A classic DP solution uses dp[i][j] to match s[:i] with p[:j].
Run tests to see results
No issues detected