Extracting only characters from a string in Python

前端 未结 7 1174
后悔当初
后悔当初 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 07:51

    You could do it with re, but the string split method doesnt take a regex, it takes a string.

    Heres one way to do it with re:

    import re
    word1 = " ".join(re.findall("[a-zA-Z]+", st))
    

提交回复
热议问题