[Issue 17520] New: Different matches with ctRegex and regex on multiline inputs

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Jun 18 08:24:56 PDT 2017


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 at puremagic.com
          Reporter: alex.bleron at 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

--


More information about the Digitalmars-d-bugs mailing list