Regex Match-All

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Regex Match-All

danielku15
Hi everybody.

I'm a little bit confused about the regex API. I want to iterate over all matches of a string. How can I do that using EReg?

I expect something like that:

var r:EREg = ~/^//(.*)$/m;

var s = "//Match1\n//Match2\n  /* Test */\n//Match3";

var matcher = r.matcher(s);

while(matcher.next()) {
    trace(matcher.group(1));
}

prints:
Match1
Match2
Match3

I probably thought of using matchedRight somehow to get the substring to use for the next match call. But is this correct?

Greetings
Daniel