Search code examples
pythonpython-re

Python Re: How to match any string that has at least 1 letter?


I just want to match any string that has at least 1 letter. See example below. Thanks

import re

string1= "23  2021Sep Oct2021 Pte. 9K8 Ltd,"

Desired Outcome --> ['2021Sep' ,'Oct2021', 'Pte', '9K8', 'Ltd']

Solution

  • You could do without re like this:

    [''.join(cc for cc in w if cc.isalnum()) for w in string1.split() if any(c.isalpha() for c in w)]
    

    that outputs

    ['2021Sep', 'Oct2021', 'Pte', '9K8', 'Ltd']