www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17520] New: Different matches with ctRegex and regex on

https://issues.dlang.org/show_bug.cgi?id=17520

          Issue ID: 17520
           Summary: Different matches with ctRegex and regex on multiline
                    inputs
           Product: D
           Version: D2
          Hardware: x86_64
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: alex.bleron gmail.com

ctRegex and regex give different matches in the following example:

///////////////////////////////////////////
import std.regex;
import std.stdio;

auto directivesRegexp = regex(`(.*)`);
auto ctDirectivesRegexp = ctRegex!(`(.*)`);

immutable text = `line1
line2

line3
`;

void main()
{
    writeln("REGEX");
    foreach (m; matchAll(text, directivesRegexp))
    {
        writefln("match=%s", m[1]);
    }
    writeln("CTREGEX");
    foreach (m; matchAll(text, ctDirectivesRegexp))
    {
        writefln("match=%s", m[1]);
    }
}

///////////////////////////////////////////
Output:

REGEX
match=line1
match=
match=line2
match=
match=    
match=
match=line3
match=
match=
CTREGEX
match=line1
match=line2
match=    
match=line3
match=

///////////////////////////////////////////
I think the behavior of ctRegex is the correct one in this case.

DPaste:
https://dpaste.dzfl.pl/43c4a1991357

--
Jun 18 2017