Please ask a written test question of Alibaba (about regular): coding question 2: matching similar to wildcards

Encoding question 2: matching similar to wildcards
description: implementation supports"." The rules for matching similar wildcards with"* "are as follows:

  1. "." Match any single character
  2. "* "matches zero or more previous elements
  3. isMatch (s, r); s is the matching target string, r is the string with matching characters
  4. The match of
  5. r should override s

example:

isMatch("aa","a") // return false
isMatch("aa","aa") // return true
isMatch("aaa","aa") // return false
isMatch("aa", "a*") // return true
isMatch("aab", "a*") // return false
isMatch("aa", ".*") // return true
isMatch("ab", ".*") // return true
isMatch("ab", ".a") // return false
isMatch("ab", ".b") // return true
isMatch("aab", "c*a*b") // return true

function isMatch(s, r) {
  /*  */
}

so how should I write it? I really couldn"t figure it out at that time. The brain may be useless

Aug.20,2021

function isMatch(s, r){
    return new RegExp(`^${r}$`, 'g').test(s);
}
// . * 
// new RegExp()
//  ^$
//  'g'

Gee, after being reminded by the comment area that this is an algorithm problem, I didn't pay attention to it, which was embarrassing. This is actually leetcode 44 . The owner of the question can go to search to see the relevant answers. Such as this: Wildcard Matching

Menu