Capture offset of matches in std.regex.matchAll?
JD via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 7 14:32:29 PDT 2014
I'm using a compile time regex to find some tags in an input
string. Is it possible to capture the offset of the matches in
some way? Otherwise I have to "calculate" the offsets myself by
iterating over the results of matchAll.
Thanks,
Jeroen
---
Example code:
import std.stdio;
import std.regex;
void main()
{
auto input = "<html><body><p>{{ message }}</p></body></html>";
auto ctr = ctRegex!(`(\{\{|\{\%|\{\#)?`, "s");
auto matches = matchAll(input, ctr);
/*
auto offset = 0;
foreach(match;matches)
{
writeln(offset, ":", match);
++offset;
}
*/
}
More information about the Digitalmars-d-learn
mailing list