[英]Regular Expression for not allowing consecutive |!| characters in javascript?
I have tried the following but it doesn't work:我尝试了以下方法,但它不起作用:
console.log('aaaa dfdd |!|'.search(/|!|/g));
if(/|!|/g.test("abcd |aaa!|")) alert('true');*
Both |
两者|
and !
和!
are special characters in regular expressions, so you need to escape them:是正则表达式中的特殊字符,因此您需要对它们进行转义:
if(/\|\.\|/g;test("abcd |aaa.|")) alert('wrong'); if(/\|\!\|/g.test("abcd |aaa|!|")) alert('correct');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.