Answer by Be Champzz for Find the indexes of all regex matches?
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},...
View ArticleAnswer by Omkar Rahane for Find the indexes of all regex matches?
This should solve your issue:pattern=r"(?=(\"[^\"]+\"|'[^']+'))"Then use the following to get all overlapping indices:indicesTuple = [(mObj.start(1),mObj.end(1)-1) for mObj in re.finditer(pattern,input)]
View ArticleAnswer by Dave Kirby for Find the indexes of all regex matches?
This is what you want: (source)re.finditer(pattern, string[, flags]) Return an iterator yielding MatchObject instances over all non-overlapping matches for the RE pattern in string. The string is...
View ArticleFind the indexes of all regex matches?
I'm parsing strings that could have any number of quoted strings inside them (I'm parsing code, and trying to avoid PLY). I want to find out if a substring is quoted, and I have the substrings index....
View Article