本文介绍了仅从 Python 中的字符串中提取字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Python 中,我只想从字符串中提取字符.
In Python, I want to extract only the characters from a string.
考虑我有以下字符串,
input = "{('players',): 24, ('year',): 28, ('money',): 19, ('ipod',): 36, ('case',): 23, ('mini',): 46}"我想要的结果是,
output = "players year money ipod case mini"我试图只考虑字母来拆分,
I tried to split considering only the alphabets,
word1 = st.split("[a-zA-Z]+")但是分裂并没有发生.
推荐答案你可以用 re 来做,但是字符串拆分方法不需要正则表达式,它需要一个字符串.
You could do it with re, but the string split method doesnt take a regex, it takes a string.
这是使用 re 的一种方法:
Heres one way to do it with re:
import re word1 = " ".join(re.findall("[a-zA-Z]+", st))更多推荐
仅从 Python 中的字符串中提取字符
发布评论