Hi,

While solving Advent of Code problems for fun (already discussed in the forum: http://forum.dlang.org/post/cwdkmblukzptsrsrv...@forum.dlang.org), I ran into an issue. I wanted to test for the pattern "two consecutive characters, arbitrary sequence, the same two consecutive characters". Sadly, my solution using regular expressions gave a wrong result, but a hand-written one was accepted.

The problem reduced to the following:

import std.regex, std.stdio;
void main ()
{
        writeln (bmatch   ("abab",  r"(..).*\1"));  // [["abab", "ab"]]
        writeln (match    ("abab",  r"(..).*\1"));  // [["abab", "ab"]]
        writeln (matchAll ("abab",  r"(..).*\1"));  // [["abab", "ab"]]
        writeln (bmatch   ("xabab", r"(..).*\1"));  // [["abab", "ab"]]
        writeln (match    ("xabab", r"(..).*\1"));  // []
        writeln (matchAll ("xabab", r"(..).*\1"));  // []
}

As you can see, bmatch (usage discouraged in the docs) gives me the result I want, but match (also discouraged) and matchAll (way to go) don't.

Am I misusing matchAll, or is this a bug?

Ivan Kazmenko.

Reply via email to