(?=...)
foo(?=bar)
匹配 foo,仅当其后紧跟 bar 时匹配,但 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']