How to file all matches and start index of all the numbers in a string with Python

1 Answer

0 votes
import re

s = "3 64 983 6721"

for match in re.finditer("\d+", s):
    print("index:", match.start(), " ", match.group(0))


'''
run:

index: 0   3
index: 2   64
index: 5   983
index: 9   6721

'''

 



answered Sep 1, 2018 by avibootz
...