std.regexp vs std.regex [Re: RegExp.find() now crippled]

Steve Teale steve.teale at britseyeview.com
Mon Nov 15 07:55:42 PST 2010


KennyTM~ Wrote:

> On Nov 15, 10 14:58, Steve Teale wrote:
> > Some time ago in phobos2, the following:
> >
> >     RegExp wsr = RegExp("(\\s+)");
> >     int p = wsr.find("<thingie att1=\"whatever\">");
> >     writefln("%s|%s|%s %d",wsr.pre(),  wsr.match(1), wsr.post(), p);
> >
> > would print:
> >
> > <thingie| |att1="whatever">  7
> >
> > Now it prints
> >
> > <thingie| |att1="whatever">  1
> >
> > The new return value is pretty useless, equivalent to returning a bool. It seems to me that the 'find' verb's subject should be the string, not the RegExp object.
> >
> > This looks like a case of the implementation being changed to match the documentation, when in fact it would have been better to change the documentation to match the implementation.
> >
> > Either that, or RegExp should have an indexOf method that behaves like string.indexOf.
> >
> > Steve
> >
> 
> Isn't std.regexp replaced by std.regex? Why are both of them still in 
> Phobos 2?
> 
> (oh, and std.regex is missing a documented .index (= .src_start) property.)

I guess std.regexp is still there because not all of us necessarily want to iterate a range to simply find out the position of the first whitespace in a string. Part of the expressiveness of languages is that one should be free to use the style that suits, and not have to read the documentation every time one uses it. Give me options in Phobos by all means.

D2 is not going to succeed by forcing its users to use unfamiliar, and maybe not yet very fashionable constructions.

I'm pissed off because this change broke a lot of my code, which I had not used for some time, but now have a paying customer for. The code did not break because of D language evolution. It broke because somebody decided they did not like the style of std.regexp.  All I wanted was plain old regular expressions, similar to JavaScript, or PHP, or other popular languages, and std.regexp did that pretty well at one time.

Steve



More information about the Digitalmars-d mailing list