[Issue 11765] New: std.regex: Negation of character class is not applied to base class first
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Dec 18 11:37:09 PST 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11765
Summary: std.regex: Negation of character class is not applied
to base class first
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: andrej.mitrovich at gmail.com
--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-12-18 11:37:06 PST ---
-----
import std.regex;
import std.stdio;
void main()
{
// expected: [["3"]] - but got: [["2"]]]
writeln("123456789".match("[^1--[2]]"));
// the above is *currently* equivalent to:
writeln("123456789".match("[^[1--[2]]]"));
// which means: subtract "1 - 2" (equals 1),
// and then negate it (so "2" will match first in the string)
// but I expect the first case to be equivalent to:
writeln("123456789".match("[[^1]--[2]]"));
// which means: negate 1 (for discussion assume 2-9 range),
// subtract 2 and you get 3-9, which means "3" will match first.
}
-----
I'm not sure whether this is just how ECMAScript does it (since std.regex
references it), but e.g. .NET does negation on the base class first (The "1"
class above) and *then* it does subtraction with another class.
You can test this behavior here:
http://refiddle.com/
Using .net syntax:
[^01-[2]]
0123456789
It matches "3".
Either way if this report is invalid (e.g. expected behavior) then I think we
should update the docs so they state the precedence of the negation.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list