Regex match in for loop

seany via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 15 13:18:55 PDT 2014


Consider this:

import std.stdio, std.regex, std.array, std.algorithms ;

void main(string args[])
{

string[] greetings = ["hello", "hallo", "hoi", "salut"];

regex r = regex("hello", "g");

for(short i = 0; i < greetings.count(); i++)
{

   auto m = match(greetings[i], r);
}

}

To the best of my knowledge, declaring a variable inside a for 
loop is illegal, you can not delacre the same variable repeatedly 
over the iterations.

Also just the declaration auto m; outside the for loop does not 
make sense either - auto needs an Right Hand Side expression.

So what is the correct way of doing it?


More information about the Digitalmars-d-learn mailing list