Python Re:如何匹配任何至少有1个字母的字符串?



我只想匹配任何至少有1个字母的字符串。参见下面的示例。由于

import re
string1= "23  2021Sep Oct2021 Pte. 9K8 Ltd,"
Desired Outcome --> ['2021Sep' ,'Oct2021', 'Pte', '9K8', 'Ltd']

你可以这样做:

[''.join(cc for cc in w if cc.isalnum()) for w in string1.split() if any(c.isalpha() for c in w)]

输出
['2021Sep', 'Oct2021', 'Pte', '9K8', 'Ltd']

最新更新