What's the right way to test if regex.match() hits or not?
Russell Lewis
webmaster at villagersonline.com
Mon Jun 1 21:16:10 PDT 2009
I'm trying to use regex.match() for a tokenizer. So I want to compare
my input to a bunch of different regex'es, expecting one to hit and the
rest not to.
Problem is, I can't seem to figure out the "right" way to ask if a hit
occurred. My code is roughly this:
BEGIN CODE
while(input.length > 0)
{
auto r1 = regex("^...something nasty...");
auto r2 = regex("^...something worse...");
auto tmp = match(input, r1);
if(<check r1 here>)
{
ReportTokenType1(tmp.hit())
input = tmp.post();
continue;
}
... and so on ...
}
END CODE
What do I put inside the if()?
P.S. Does anybody know why dmd complains "cannot evaluate at compile
time" when I set those regex objects to "static invariant" so I'm not
rebuilding them with every pass?
More information about the Digitalmars-d-learn
mailing list