Finding all regex matches by index?
- From: Roy Smith <roy@xxxxxxxxx>
- Date: Tue, 29 May 2012 21:33:29 -0400
I have a long string (possibly 100s of Mbytes) that I want to search for
regex matches. re.finditer() is *almost* what I want, but the problem
is that it returns matching strings. What I need is a list of offsets
in the string where the regex matched. Thus:
s = "this is a string"
find("is", s) => [2, 5]
Is there anything that does this?
.
Relevant Pages
- Re: Question: Optional Regular Expression Grouping
... The core problem is that the regex matches ... that ambiguity; it merely attempts to make the module prefer the match ... the pattern rather than in the string literal. ... (comp.lang.python) - Re: Trouble with regular expressions
... returns a value greater than -1, indicating the string is found. ... I'm missing something fundamental about regular expressions. ... m1.matchesmeans "the regex matches the WHOLE STRING", ... (comp.lang.java.programmer) - Re: Regular expressions question
... Yes: I said that the regex matches an empty string: So here you match ... A regex can contains whitespaces!! ... (microsoft.public.dotnet.languages.vc) - Re: pattern match
... with the /x modifier it matches and assigns the string you ... Remember that greediness never affects whether a regex matches or not. ... Gunnar Hjalmarsson ... (comp.lang.perl.misc) - Re: java String split returns an additional first empty string
... > array of Strings. ... I always get the first String in the array as an ... So you will get an empty string if the regex matches the 1st part of the ... (comp.lang.java.programmer) |
|