(?<!...)
(?<!foo)bar
匹配 bar,仅当其前面没有 foo 时匹配。
解释:
import re
pattern = r'(?<!foo)bar'
test_string = 'foobar quxbar'
matches = re.findall(pattern, test_string)
print(matches) # ['bar']
const pattern = /(?<!foo)bar/g;
const testString = 'foobar quxbar';
const matches = testString.match(pattern);
console.log(matches); // ['bar']