首页 > 解决方案 > Python Re:如何匹配任何至少有 1 个字母的字符串?

问题描述

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

import re

string1= "23  2021Sep Oct2021 Pte. 9K8 Ltd,"

Desired Outcome --> ['2021Sep' ,'Oct2021', 'Pte', '9K8', 'Ltd']

标签: pythonre

解决方案


你可以像这样没有 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']

推荐阅读