[Issue 941] New: std.regexp fails to match when grouping certain sub-expressions
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Feb 8 09:31:01 PST 2007
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 at digitalmars.com
ReportedBy: tom_dlang at 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;
--
More information about the Digitalmars-d-bugs
mailing list