Quantcast
Channel: Find the indexes of all regex matches? - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Answer by Be Champzz for Find the indexes of all regex matches?

$
0
0

To get indice of all occurences:

S = input() # Source String k = input() # String to be searchedimport repattern = re.compile(k)r = pattern.search(S)if not r: print("(-1, -1)")while r:    print("({0}, {1})".format(r.start(), r.end() - 1))    r = pattern.search(S,r.start() + 1)

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>