这里是我的字符串:如果它不包含特定单词,我该如何匹配它?
$str = "this is a string
this is a test string";
我想匹配的一切this
与字之间string
(加上本身)。
注意:这两个词之间可以是除了test
之外的所有词。
所以我试图匹配this is a string
,但不是this is a test string
。因为第二个包含test
这个词。
这是我目前的格局:
/this[^test]+string/gm
But it doesn't work as expected
我怎样才能解决呢?
我没有得到'test'部分。请你解释一下 – mrid
@mrid我想匹配每个以'this'开头并以'string'结尾的句子,如果该句子不包含'test'的话。 – Shafizadeh
@mrid反之亦然https://regex101.com/r/ENHYLD/3 – Shafizadeh