题解 | #字符串通配符#

字符串通配符

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));
    }
});

全部评论

相关推荐

用微笑面对困难:只要你保证项目和获奖都是真的就行尤其是“对战,总负责人”啊这些套职,基本上队员,打杂的都这么写
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务