Extracting only characters from a string in Python

前端 未结 7 1189
后悔当初
后悔当初 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:42

    I think that you want all words, not characters.

    result = re.findall(r"(?i)\b[a-z]+\b", subject)
    

    Explanation:

    "
    \b       # Assert position at a word boundary
    [a-z]    # Match a single character in the range between “a” and “z”
       +        # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
    \b       # Assert position at a word boundary
    "
    

提交回复
热议问题