Is str ~ regex the root of all evil, or the leaf of all good?
Daniel Keep
daniel.keep.lists at gmail.com
Thu Feb 19 22:31:26 PST 2009
Benji Smith wrote:
>>> And how do you combine them? "repeat, ignorecase"? Writing and
>>> parsing such options becomes a little adventure in itself. I think
>>> the "g", "i", and "m" flags are popular enough if you've done any
>>> amount of regex programming. If not, you'll look up the manual
>>> regardless.
>>>
>>
>> Perhaps, string.match("a[b-e]", Regex.Repeat | Regex.IgnoreCase);
>> might be better? I don't find "gmi" immediately clear nor
>> self-documenting.
>
> I prefer the enum options too. But not vociferously. I could live with
> the single-char flags.
>
> --benji
I dislike enum options because it dramatically bloats the code, in terms
of how much typing it takes.
This is another thing that Visual Basic actually got right [1]; instead of:
Match(string, "a[b-e]", Regex.Repeat | Regex.IgnoreCase)
you could use this:
Match(string, "a[b-e]", Repeat | IgnoreCase)
Since the compiler knew the type of that third argument, it allowed you
to omit the prefix.
If D did that, I would completely reverse my dislike of enums and
DEFINITELY prefer them over strings; you could always have this:
enum Regex
{
Repeat,
IgnoreCase,
R = Repeat,
I = IgnoreCase,
}
And then instead of "ri" you have R|I which is actually shorter AND safer!
But yeah; I think Walter said he wanted to do this ages and ages ago,
but it never happened.
-- Daniel
[1] It's funny how many things that poor language *did* get right. I
mean, yeah, it's a terrible language from a design standpoint, but boy
did it ever let you just get shit done.
More information about the Digitalmars-d
mailing list