Harry Ohlsen
11/19/2003 10:46:00 PM
gabriele renzi wrote:
>>While using a regex to do something so simple seems a bit excessive, looking for a value at the start or end of a string is really just a special case of a more general problem, which regex matching solves very neatly.
>
>
> well, IMO It is less error prone, may be implemented in a faster way,
True. I must say, I was surprised there weren't built-in methods for these.
> and is more clear to the casual reader.
I guess what I was getting at is that regexes are such a useful tool that I would hope most Ruby programmers would be pretty conversant with them ... and the necessary regexes in this case are about as simple as you can get.
> Plus, like every builtin it avoide reinventing the weel.
Of course, they're not very big wheels :-).
> Did you noticed 4 people gave 3 different answers?
Although, there were really only two, since "s =~ /^Hello/" is syntactic sugar for "/^Hello/.matches(s)".
Ie, there were "use regexes" or "use this extension".
> another quick way to do it :
> if 'ciao'[/iao$/]
TMTOWTDI ... put it down to Matz providing perl compatibility :-).