我谨此陈辞:
words = ['001operating', '1002application', '3aaa0225', '-setup', '--setup']
我需要在单词前删除任何非字母字符。预期结果如下:
processed = ['operating', 'application', 'aaa0225', 'setup', 'setup']
这就是我到目前为止所做的:
import re
processed = []
for w in words:
w = re.sub(r"(?<!\S)", "", w)
processed.append(w)
有什么建议吗
你可以用
使用PyPi ^{} module ,您可以使用
详细信息
^
-字符串的开头(此处与\A
相同)[\W\d_]+
-匹配任何非单词、数字或下划线字符\P{L}+
-除任何Unicode字母外的一个或多个字符李>见a Python demo:
相关问题 更多 >
编程相关推荐