Pattern matching with . and *

Write matches(text, pattern) that returns whether the whole of text matches pattern, where . matches any single character and * means "zero or more of the preceding element". Patterns are valid: * never comes first.

matches("aa", "a")     ->  False
matches("aa", "a*")    ->  True
matches("ab", ".*")    ->  True
matches("aab", "c*a*b")  ->  True
matches("mississippi", "mis*is*p*.")  ->  False

A two-index DP: ok[i][j] means text[i:] matches pattern[j:]. The * case branches into "skip the pair" or "consume one character and stay".

def matches(text, pattern):
    ...