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

2024-10-01 05:01:47 发布

您现在位置:Python中文网/ 问答频道 /正文

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

import re

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

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

Tags: 字符串importre字母例子ltddesiredstring1
1条回答
网友
1楼 · 发布于 2024-10-01 05:01:47

你可以不这样做:

[''.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']

相关问题 更多 >