📜  javascript switch case regex - Javascript代码示例

📅  最后修改于: 2022-03-11 15:02:32.091000             🧑  作者: Mango

代码示例1
var regex1 = /a/,
    regex2 = /b/,
    regex3 = /c/,
    samplestring = 'b';

switch (true) {
    case regex1.test(samplestring):
        console.log("regex1");
        break;
    case regex2.test(samplestring):
        console.log("regex2");
        break;
    case regex3.test(samplestring):
        console.log("regex3");
        break;
}