On Thu, 07 Aug 2014 16:05:16 +0000, seany wrote:

> 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?

You're not really using regexes properly.  You want to greedily match as 
much as possible in this case, e.g.:

void main()
{
        import std.regex;
        auto re = regex("ab(cd)?");
        assert("PREabcdPOST".matchFirst(re).hit == "abcd");
        assert("PREabPOST".matchFirst(re).hit == "ab");

}

Reply via email to