earthquake changes of std.regexp to come
Jarrett Billingsley
jarrett.billingsley at gmail.com
Tue Feb 17 19:42:07 PST 2009
On Tue, Feb 17, 2009 at 9:38 PM, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> By the way, the more I dig into std.regexp, the stiffer the hair on my neck
> gets. Get this: the API offers both global functions and member functions,
> with both RegExp and plain string arguments. The latter are carefully
> designed to maximize the number of clashes, potential confusions, and errors
> when using both std.string and std.regex.
>
> But wait, there's more. The API defines the following functions that all
> ostensibly do some sort of mattern patching (sic): find, search, test,
> match, and exec. I wish I were kidding. There's some opIndex and opEquals
> thrown in for good measure. Knuth wouldn't know what each of them does after
> studying them for a week and then watching an episode from "The Bachelor".
> And get this: global search() does not do what member search() does. Nope.
> Global search() does what member test() does. I have only contempt for such
> designs.
Well I don't mean to, uh, toot my own horn but.. I recently bound
libpcre to MiniD and came up with a relatively simple but powerful and
orthogonal API.
http://www.dsource.org/projects/minid/wiki/Addons/PcreLib#LibraryReference
The regex object has a single "subject" string at a time, the string
that it's matching against. The subject is set with "search" and
"test" does everything. All other functions are basically defined in
terms of those two. "test" looks for the next match of the regex in
the subject and returns true if it matched. "match" returns match
groups (0 for the whole regex and 1..n for subgroups, as well as
string indices for named subgroups). opApply is just a quicker way
of writing something like:
re.search(someSubject)
while(re.test())
// use re.match to get matches
You'll notice that opApply is also just defined in terms of test.
I've found it far more intuitive than other APIs. I've never used
Perl and I doubt I ever will, though.
More information about the Digitalmars-d
mailing list