bearophile wrote:
Andrei Alexandrescu:

foreach (i; 0 .. iter.captures) writeln(iter.capture(i));

"Capture" is the traditional term as far as I understand. I can't
use .length because it messes up with range semantics. "len" would
be too confusing. "ncaptures" is too cute. Nobody's perfect :o).

"group" may be a struct that defines toString and can be cast to
string, and also keeps the starting position of the group into
the original string.

That sounds good.

Well, then match() may return just a dynamic array of such
groups/captures. So such array has both .length and opIndex. It looks
simple :-)

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

Reply via email to