Menu
CoddyTech

Regular Expression Matching

You get a string s and a pattern p. In the pattern, a letter matches that same letter, a dot . matches any one letter, and a star * means zero or more copies of the element right before it, which is a letter or a dot. Return true if the pattern matches the whole of s, not only a part of it, and false otherwise.

Function

isMatch(s: string, p: string) → boolean
sstring
the string to match, lowercase letters only
pstring
the pattern of letters, dots and stars
Returnsboolean
true if p matches all of s, false otherwise

Constraints

  • 1 ≤ s.length ≤ 1000
  • 1 ≤ p.length ≤ 1000
  • s contains only lowercase English letters.
  • p contains only lowercase English letters, . and *.
  • Every * follows a letter or a ., so p never starts with * and never has two stars in a row.

Examples

Input
s = "moon"p = "mo*n"
Output
true
Explanation
o* takes both o letters, so m, o* and n spell moon exactly.

lock icon+29 hidden tests on Submit

challenge icon

Follow-up

Can you also support +, one or more copies of the element before it, with the same table?

Reset code
def isMatch(s, p):
    # Write code here
Test cases

Case 1

Case 2

Case 3

Input

s = "moon"
p = "mo*n"

Expected

true