题解 | #正则表达式匹配#
正则表达式匹配
https://www.nowcoder.com/practice/28970c15befb4ff3a264189087b99ad4
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param str string字符串 * @param pattern string字符串 * @return bool布尔型 */ function match(str, pattern) { if (pattern === ''&&str === '') { return true; } const firstMatch = (str !== '') && (str[0] === pattern[0] || pattern[0] === '.'); if (pattern.length >= 2 && pattern[1] === '*') { return (match(str, pattern.slice(2)) || (firstMatch && match(str.slice(1), pattern))); } else { return firstMatch && match(str.slice(1), pattern.slice(1)); } } module.exports = { match: match, };