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