[英]RegEx javascript match 2 consecutive occurence of character but not more
我需要有关正则表达式的帮助。 我必须在字符串的开头匹配“ {{”,但不必匹配“ {{{””。 我尝试使用^[{]{2}
但它与“ {{{””匹配。 我尝试将“ {{{””与^[^{]{3}
匹配,但我不知道如何再次匹配“ {{”。
我知道我可以使用if语句解决它。 但是我想在正则表达式中一次性完成。 任何想法?
^{{[^{]
或^[{]{2}[^{]
都可以
^ asserts position at start of a line
{{ matches the characters {{ literally (case sensitive)
Match a single character not present in the list below [^{]
{ matches the character { literally (case sensitive)
使用负前瞻:
const re = /^{{(?!{)/; console.log("{{{".match(re)); console.log("{{a".match(re));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.