How to match sequences without specific character from a string with regular expression in Python

1 Answer

0 votes
import re     

s = 'xyx - aaxx .aaayyy -aaaxyxxyyaaa.'    
pattern = '[^- ]+'  # sequences without - and space

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

Found: 'xyx'
Found: 'aaxx'
Found: '.aaayyy'
Found: 'aaaxyxxyyaaa.'

'''

 



answered Apr 27, 2019 by avibootz
...