P
Paul Rubin
I have a string s, possibly megabytes in size, and two regexps, p and q.
I want to find the first occurence of q that occurs after the first
occurence of p.
Is there a reasonable way to do it?
g1 = re.search(p, s)
g2 = re.search(q, s[g1.end():])
q_offset = g1.end() + g2.start()
is not a reasonable way, since it copies a ton of data around
(slicing an arbitrary sized chunk off s into a new temporary string).
Most regexps libs I know of have a way to start the search at a
specified offset. Python's string.find and string.index methods
have a similar optional arg. But I don't see it described in the
re module docs.
Am I missing something?
Thanks.
I want to find the first occurence of q that occurs after the first
occurence of p.
Is there a reasonable way to do it?
g1 = re.search(p, s)
g2 = re.search(q, s[g1.end():])
q_offset = g1.end() + g2.start()
is not a reasonable way, since it copies a ton of data around
(slicing an arbitrary sized chunk off s into a new temporary string).
Most regexps libs I know of have a way to start the search at a
specified offset. Python's string.find and string.index methods
have a similar optional arg. But I don't see it described in the
re module docs.
Am I missing something?
Thanks.