开发者

test1 alert appears, test2 alert doesn't - invalid regex between them?

开发者 https://www.devze.com 2022-12-13 11:17 出处:网络
alert(\'test1\'); var re = new RegExp(\"(http://(?:[A-Za-z0-9-]+\\\\.)?[A-Za-z0-9-]+\\\\.[A-Za-z0-9-]+/?)\", \"si\");
alert('test1');
var re = new RegExp("(http://(?:[A-Za-z0-9-]+\\.)?[A-Za-z0-9-]+\\.[A-Za-z0-9-]+/?)", "si");
alert('test2');

Why is this happening? How开发者_Go百科 to solve this problem?


The "s" is the problem, it's not a valid modifier for javascript regular expressions. The only valid modifiers are /g (global) /i (case-insensitive) and /m (multi-line).

0

精彩评论

暂无评论...
验证码 换一张
取 消