我可以轻松编写一个正则表达式来匹配包含两个连续重复字符的字符串:
/(\w)\1/
如何进行补集操作?我想匹配不含有两个连续重复字符的字符串。我尝试了以下各种变化,但都没有成功:
/(\w)[^\1]/ ;doesn't work as hoped
/(?!(\w)\1)/ ;looks ahead, but some portion of the string will match
/(\w)(?!\1)/ ;again, some portion of the string will match
我不想使用任何特定于语言/平台的方式来对正则表达式取反。我想要一个直接简单的方法来实现这一点。
^(?!.*(\w)\1).*
- Avinash Raj