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: [email protected]
          Reporter: [email protected]

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.)

--

Reply via email to