How to match sequences of digits from string with regular expression in Python

1 Answer

0 votes
import re     

s = 'xyx 234 aa44XY.aaAyyy984aABCaxYxx3yYaxaa.'    
pattern = r'\d+'  # sequence of digits

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

Found: '234'
Found: '44'
Found: '984'
Found: '3'

'''

 



answered Apr 27, 2019 by avibootz
...