tags:

views:

98

answers:

1

Perhaps I'm going about this all wrong, but I'm trying to get all the matches in a string for a particular regex pattern. I'm using re-matcher to get a Match object, which I pass to re-find, giving me (full-string-match, grouped-text) pairs. How would I get a sequence of all the matches produced by the Match object?

In Clojuresque Python, it would look like:

pairs = []
match = re-matcher(regex, line)

while True:
    pair = re-find(match)
    if not pair: break
    pairs.append(pair)

Any suggestions?

+8  A: 
Alex Stoddard
That's what I'm looking for, but I'm getting a different result: a vector of lists, not a vector of strings.
Colorado
Did you mean a 'sequence of vectors'? That is what would be returned if you have group capturing in your regex. I have added some more examples above.
Alex Stoddard
You're right: I must have meant 'sequence of vectors'. Your examples have cleared things up for me. Thanks.
Colorado