Is str ~ regex the root of all evil, or the leaf of all good?

Bill Baxter wbaxter at gmail.com
Fri Feb 20 11:43:39 PST 2009


On Fri, Feb 20, 2009 at 9:59 PM, Sergey Gromov <snake.scaly at gmail.com> wrote:
> Thu, 19 Feb 2009 07:46:47 -0800, Andrei Alexandrescu wrote:
>
>> The argument could go both ways:
>>
>> "Organize the set of 2-char strings starting with 'c' and ending with
>> 'a' to 'z' into a structured haystack, then look for substrings of
>> "conoco" in that haystack."
>>
>> versus
>>
>> "Given the unstructured haystack conoco, look for a structured needle in
>> it that is any 2-char string starting with 'c' and ending with 'a' to 'z'."
>>
>> What is the most natural way?
>
> I think calling a regex a 'haystack' is a far-fetched metaphor.  A
> haystack is a pile of stuff, and a needle is a precise thing you're
> looking for.  I think they're unambiguous.

I thought so too.  It's a stretch.  And I also agree with the various
posts people have made about allowing plain char[] search strings to
be interchangeable with regex'es as much as possible.  And in that
light saying you're looking for [big-string] inside of [sub-string]
just sounds ridiculous.  But a string is certainly a kind of
special-case regex that just describes a set consisting 1 element.  So
yeh, you /could/ say you're looking for matches inside that set, but
it's quite a stretch.

> Also, the in operator doesn't leave you guessing whether you should put
> a haystack or a needle first.

That's a good point in it's favor.  As long as you aren't one of these
folks who thinks "looking for matches inside a regular grammar" is
just as reasonable as "looking for a pattern inside a string".

--bb



More information about the Digitalmars-d mailing list