www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19979] New: std.regex should return null for non-matched

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

          Issue ID: 19979
           Summary: std.regex should return null for non-matched captures
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P4
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: dlang-bugzilla thecybershadow.net

Consider this D program:

void main()
{
        auto m = matchFirst("bad", `^(?P<negation>not )?bad$`);
        assert(m);
        assert(!m["negation"]);
}

Currently, the assertion will fail, even though the capture "negation" was not
found in the sought string.

Ideally, std.regex would return "null" in this circumstance. (Currently, it
returns input[0..0], which is a true-ish value.)

--
Jun 17 2019