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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jun 17 20:41:05 UTC 2019


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 at puremagic.com
          Reporter: dlang-bugzilla at 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.)

--


More information about the Digitalmars-d-bugs mailing list