The following failed for more than six digits:
auto rx_bf_ddd = regex( r"(?<=\d)(?=(\d\d\d)+\b)", "g");
writefln( "rx_bf_ddd: %s ", replace(digits, rx_bf_ddd, ",") );
Using (\d{3}) i/o (\d\d\d) worked.
DMD64 D Compiler v2.060
Comment #1 by dmitry.olsh — 2012-12-27T08:15:19Z
Now that was neasty.
The bug lurked in a branch-test code of *-repetition. It was too optimistic optimization and it was curbed down back then. Looks like one case slipped through.
The reduced test case doesn't require lookahead at all:
version A1 prints [["123", "12", "3"]] (!!)
version A2 prints [["1234", "3", "4"]]
The bug is triggered in a specific scenarios but is quite deadly.
import std.regex, std.stdio;
int main(string[] args)
{
version(A1)
{
auto rx_1 = regex(r"^(\w)*(\d)");
auto m = match("1234", rx_1);
auto captures = m.front;
writefln("%s", captures);
}
version(A2)
{
auto rx_2 = regex(r"^([0-9])*(\d)");
auto m2 = match("1234", rx_2);
auto captures2 = m2.front;
writefln("%s", captures2);
}
return 0;
}