我有一些问题与正则表达式,直到现在,我没有问题,除了以下一个:
我有两个字符串,我想匹配其中一个,但不匹配包含特定单词的第二个。
var text1 = "The sun is yellow and the sky is blue";
var text2 = "The sun is yellow and the clouds are white";
对于这个例子来说这是非常基本的,但是我的正则表达式之前是这样的:
var regex = /sun/g;
这对于text1是可以的但是现在我想返回false如果字符串包含"clouds"所以text1是TRUE而text2不是
我试过(?!云),但我可能做错了。在这个级别上很难使用正则表达式。所以我希望你能帮助我。
谢谢
可以这样做:
^(?!.*bcloudsb)(?=.*bsunb).*$
https://regex101.com/r/TYZHwS/1