Regex-Fu

Chris via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 25 04:11:49 PDT 2015


I'm a bit at a loss here. I cannot get the longest possible 
match. I tried several versions with eager operators and stuff, 
but D's regex engine(s) always seem to return the shortest match. 
Is there something embarrassingly simple I'm missing?

void main()
{
   import std.regex : regex, matchFirst;
   import std.stdio : writeln;

   auto word = "blablahula";
   auto m = matchFirst(word, regex("^([a-z]+)(hula|ula)$"));
   writeln(m);  // prints ["blablahula", "blablah", "ula"]
}

I want it to return "hula" not "ula".


More information about the Digitalmars-d-learn mailing list