import re
s = "Product desingATK 30Trace back. TheATK 30 is a nice device. "
keywords = ['ATK 30', 'PPK 50', 'HJF12 10']
pattern = fr'\s*({"|".join(sorted(map(re.escape, keywords),key=len,reverse=True))})\s*'
print(pattern) # => \s*(HJF12\ 10|ATK\ 30|PPK\ 50)\s*
print(re.sub(pattern, r' \1 ', s))
# => Product desing ATK 30 Trace back. The ATK 30 is a nice device.
蛊毒传说
相关分类