Extracting only characters from a string in Python

前端 未结 7 1188
后悔当初
后悔当初 2020-12-08 07:01

In Python, I want to extract only the characters from a string.

Consider I have the following string,

input = \"{(\'players\',): 24, (\'year\',): 28         


        
7条回答
  •  甜味超标
    2020-12-08 08:01

    string.split() doesn't take regular expressions. You want something like:

    re.split("[^a-zA-Z]*", "your string")
    

    and to get a string:

    " ".join(re.split("[^a-zA-Z]*", "your string"))
    

提交回复
热议问题