题解 | #字符串通配符#
字符串通配符
https://www.nowcoder.com/practice/43072d50a6eb44d2a6c816a283b02036
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); /** * *:匹配0个或以上的字符(注:能被*和?匹配的字符仅由英文字母和数字0到9组成,下同) * ?:匹配1个字符 */ let row = 0; let reg = undefined; let line1 = undefined; rl.on("line", function (line) { row++; if (row == 1) { line1 = line; reg = new RegExp( '^' + line .toLocaleLowerCase() .replace(/\?/g, "[a-z0-9\.]{1}") .replace(/\*+/g, "*") .replace(/\*/g, "[a-z0-9\.]{0,}") + '$', "i" ); } else { console.log(reg.test(line)); } });