简体   繁体   English

不允许连续的正则表达式 |?| javascript中的字符?

[英]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.

相关问题 正则表达式只允许不会断开链接的字符 - Regular expression allowing only characters that will not break a link 正则表达式,仅允许某些字符集 - Regular expression for allowing only a certain set of characters 正则表达式字母数字字符-允许连字符和下划线 - regular expression alphanumeric characters - allowing hyphens and underscores 不允许某些特殊字符的正则表达式 - Regular expression for not allowing some special characters 为什么javascript中的这个正则表达式仍然允许使用特殊字符[a-zA-Z1-9]? - Why is this regular expression in javascript still allowing special characters [a-zA-Z1-9 ]? javascript中正则表达式,用于开始和结束处的特殊字符以及两个之间的连续字符不起作用 - Regular expression in javascript for Special characters at Start and End and two consecutive inbetween not working Javascript正则表达式将给定字符串中的“ n”个连续字符减少为单个字符 - Javascript regular expression to reduce 'n' same consecutive characters to single character in a given string javascript正则表达式中的可选字符 - optional characters in javascript regular expression JavaScript正则表达式(带_-的字母数字字符) - JavaScript regular expression ( alphanumeric characters with _-) JavaScript 中符号字符的正则表达式 - Regular Expression for symbol characters in JavaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM