www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 941] New: std.regexp fails to match when grouping certain sub-expressions

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=941

           Summary: std.regexp fails to match when grouping certain sub-
                    expressions
           Product: D
           Version: 1.005
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: tom_dlang yahoo.com.ar


It seems like regular expression pattern matching in phobos is still pretty
buggy.

The following code shows it:

----------------------------------------
import std.regexp;
import std.stdio;

int main() {
    auto str= "foo";
    char[][] re_strs= [
             r"^(h|a|)fo[oas]$",
             r"^(a|b|)fo[oas]$",
             r"^(a|)foo$",
             r"(a|)foo",
             r"^(h|)foo$",
             r"(h|)foo",
             r"(h|a|)fo[oas]",
             r"^(a|b|)fo[o]$",
             r"[abf][ops](o|oo|)(h|a|)",
             r"(h|)[abf][ops](o|oo|)",
             r"(c|)[abf][ops](o|oo|)"
    ];

    foreach (re_str; re_strs) {
        auto re= new RegExp(re_str);
        auto matches= cast(bool)re.test(str);
        writefln("'%s' matches '%s' ? %s", str, re_str, matches);
    }

    for (char c='a'; c<='z'; ++c) {
        auto re_str= "("~c~"|)foo";
        auto re= new RegExp(re_str);
        auto matches= cast(bool)re.test(str);
        writefln("'%s' matches '%s' ? %s", str, re_str, matches);
    }

    return 0;
}
----------------------------------------

All should match but the output is:

----------------------------------------
'foo' matches '^(h|a|)fo[oas]$' ? false
'foo' matches '^(a|b|)fo[oas]$' ? true
'foo' matches '^(a|)foo$' ? true
'foo' matches '(a|)foo' ? true
'foo' matches '^(h|)foo$' ? false
'foo' matches '(h|)foo' ? false
'foo' matches '(h|a|)fo[oas]' ? false
'foo' matches '^(a|b|)fo[o]$' ? true
'foo' matches '[abf][ops](o|oo|)(h|a|)' ? true
'foo' matches '(h|)[abf][ops](o|oo|)' ? false
'foo' matches '(c|)[abf][ops](o|oo|)' ? true
'foo' matches '(a|)foo' ? true
'foo' matches '(b|)foo' ? true
'foo' matches '(c|)foo' ? true
'foo' matches '(d|)foo' ? true
'foo' matches '(e|)foo' ? false
'foo' matches '(f|)foo' ? true
'foo' matches '(g|)foo' ? false
'foo' matches '(h|)foo' ? false
'foo' matches '(i|)foo' ? false
'foo' matches '(j|)foo' ? false
'foo' matches '(k|)foo' ? false
'foo' matches '(l|)foo' ? false
'foo' matches '(m|)foo' ? false
'foo' matches '(n|)foo' ? false
'foo' matches '(o|)foo' ? false
'foo' matches '(p|)foo' ? false
'foo' matches '(q|)foo' ? false
'foo' matches '(r|)foo' ? false
'foo' matches '(s|)foo' ? false
'foo' matches '(t|)foo' ? false
'foo' matches '(u|)foo' ? false
'foo' matches '(v|)foo' ? false
'foo' matches '(w|)foo' ? false
'foo' matches '(x|)foo' ? false
'foo' matches '(y|)foo' ? false
'foo' matches '(z|)foo' ? false
--------------------------------------------

That's a weird one... 

Regards,
--
Tom;


-- 
Feb 08 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=941


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 11 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=941


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED



01:40:18 PDT ---
http://www.dsource.org/projects/phobos/changeset/2047

I disabled optimize() for now and inserted the code in this report as a
unittest. I'll leave it to Walter to re-enable optimization.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 25 2010