Very Stupid Regex question
seany via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Aug 7 09:05:16 PDT 2014
Cosider please the following:
string s1 = PREabcdPOST;
string s2 = PREabPOST;
string[] srar = ["ab", "abcd"];
// this can not be constructed with a particular order
foreach(sr; srar)
{
auto r = regex(sr; "g");
auto m = matchFirst(s1, r);
break;
// this one matches ab
// but I want this to match abcd
// and for s2 I want to match ab
}
obviously there are ways like counting the match length, and then
using the maximum length, instead of breaking as soon as a match
is found.
Are there any other better ways?
More information about the Digitalmars-d-learn
mailing list