Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
479 views
in Technique[技术] by (71.8m points)

正则表达式匹配问题

    let re = /((xx)1)/i;
    let str = "xx"; 
    console.log(re.test(str));

最外层加了个括号为什么结果就变成true了?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

可能是,你的外层括号导致了正则解析器认为造成了递归回环逻辑问题,外括号可能与1形成冲突,毕竟1是倒回去重复第几个括号里的正则

/((xx))/
/(xx)1/

以上两种正则都没有问题

可能是解析器最终处理成/(xx)/,1起了冲突,就忽略了1


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...