Is str ~ regex the root of all evil, or the leaf of all good?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Thu Feb 19 11:31:17 PST 2009
jovo wrote:
> "Andrei Alexandrescu" <SeeWebsiteForEmail at erdani.org> wrote in message
> news:gnk8te$cgl$1 at digitalmars.com...
>> Looks simple but it isn't. How do you advance to the next match?
>>
>> foreach (m; "abracadabra".match("(.)a", "g")) writeln(m.capture[0]);
>>
>> This should print:
>>
>> r
>> c
>> d
>> r
>>
>> There's need to make progress in the matching, not in the capture. How do
>> you distinguish among them?
>>
>>
>> Andrei
>
> foreach(capture; match(s, r))
> foreach(group; capture)
> writeln(group);
>
>
>
The consecrated terminology is:
foreach(match; match(s, r))
foreach(capture; match)
writeln(capture);
"Group" is a group defined without an intent to capture. A "capture" is
a group that also binds to the state of the match.
Anyhow... this can be done but things get a tad more confusing for other
uses. How about this:
foreach(match; match(s, r))
foreach(capture; match.captures)
writeln(capture);
?
Andrei
More information about the Digitalmars-d
mailing list