The developers at Amazon are developing a regex matching library for their NLP use cases. A prototype regex matching has the following requirements:
For example,
Given an array, arr, of length k containing strings consisting of lowercase English letters only and a string regex of length n, for each of them find whether the given regex matches with the string or not and report an array of strings "YES" or "NO" respectively.
Function Description
Complete the function isRegexMatching
in the editor.
isRegexMatching
has the following parameters:
- regex: A regex
- arr[k]: An array of strings
Returns
string[]: An array of strings of size k where the ith string is "YES" if the ith string in arr matches with regex, otherwise it is "NO".
🌷༊·°Credit to Alex𓂃🖊
Example 1:
Input: regex = "ab(e.r)*e", arr = ["abbeere", "abefretre"]
Output: ["NO", "YES"]
Explanation:Here, n = 9, regex = "ab(e.r)*e", k = 2, arr = ["abbeere", "abefretre"]arr[0] = "abbeere" doesn't match the regex "ab(e.r)*e". arr[1] = "abefretre" matches the regex "ab(e.r)*e", if we replace '*' with 2 occurrences of "e.r", i.e. it becomes "abe.re.re". Now, replace both '.' with 'f' and 't' respectively. Hence, the answer is ["NO", "YES"].
Example 2:
Input: regex = "..()*e*", arr = ["code", "abeee", "cd"]
Output: ["NO", "YES", "YES"]
Explanation:Here, n = 8, regex = "..()*ex", k = 3, arr = ["code", "abeeee", "cd"]arr[0] = "code" doesn't matches the regex "..()*ex". arr[1] = "abeeee" matches the regex "..()*ex", if we replace first '*' with 0 occurrences of "" (an empty string) and second '*' with 3 occurrences of "e", i.e. it becomes "..eee". Now, replace both '.' with 'a' and 'b' respectively. arr[2] = "cd" matches the regex "..()*ex", if we replace first '*' with 0 occurrences of "" and second '*' with 0 occurrences of "e", i.e. it becomes "..". Now, replace both '.' with 'c' and 'd' respectively. Hence, the answer is ["NO", "YES", "YES"].
N/A

input:
output: