How to match sequences of non-whitespace from string with regular expression in Python

1 Answer

0 votes
import re     

s = 'xyx 234 aa44XY.aaAyyy984a ABCaxYxx3yYa x aa.'    
pattern = r'\S+'  # sequence of non-whitespace

for match in re.findall(pattern, s):         
    print('Found: {!r}'.format(match))
    
    
'''
run:

Found: 'xyx'
Found: '234'
Found: 'aa44XY.aaAyyy984a'
Found: 'ABCaxYxx3yYa'
Found: 'x'
Found: 'aa.'

'''

 



answered Apr 27, 2019 by avibootz
...