Python Re: 如何匹配任何至少有 1 个字母的字符串?
Python Re: How to match any string that has at least 1 letter?
我只想匹配任何至少有 1 个字母的字符串。请参见下面的示例。谢谢
import re
string1= "23 2021Sep Oct2021 Pte. 9K8 Ltd,"
Desired Outcome --> ['2021Sep' ,'Oct2021', 'Pte', '9K8', 'Ltd']
你可以像这样不用 re:
[''.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']
我只想匹配任何至少有 1 个字母的字符串。请参见下面的示例。谢谢
import re
string1= "23 2021Sep Oct2021 Pte. 9K8 Ltd,"
Desired Outcome --> ['2021Sep' ,'Oct2021', 'Pte', '9K8', 'Ltd']
你可以像这样不用 re:
[''.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']