Is str ~ regex the root of all evil, or the leaf of all good?

bearophile bearophileHUGS at lycos.com
Thu Feb 19 10:27:00 PST 2009


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 :-)

Bye,
bearophile



More information about the Digitalmars-d mailing list