← Back to index
|
Original Bugzilla link
Bug 941 – std.regexp fails to match when grouping certain sub-expressions
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
phobos
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2007-02-08T11:30:00Z
Last change time
2014-02-16T15:26:21Z
Assigned to
andrei
Creator
tom_dlang
Comments
Comment #0
by tom_dlang — 2007-02-08T11:30:54Z
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;
Comment #1
by andrei — 2010-09-25T01:40:18Z
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.