Brian Candler
4/7/2005 8:05:00 AM
On Thu, Apr 07, 2005 at 03:47:15PM +0900, Han Holl wrote:
> On Apr 6, 2005 4:58 PM, Warren Brown <warrenb@timevision.com> wrote:
> > Han,
> [ cut ]
> >
> > Because /^/ matches the beginning of a line (not the beginning of
> > the string), and /\s/ matches whitespace, which includes newlines (\n).
> > So the first place in the string where the beginning of a line is
> > followed by one or more whitespaces is at position 8.
> >
> Thanks for the reactions to all.
>
> It's not that simple: ^ _also_ matches the beginning of the string.
> Perl does _not_
> produce a match, unless you suffix the regular expression with m.
And so it's worth pointing out that in Ruby you should write:
str.untaint if str =~ /\A[a-z0-9]*\z/ # good
and not:
str.untaint if str =~ /^[a-z0-9]*$/ # HIGHLY DANGEROUS
It means that these sorts of regexp are a bit less readable than Perl's.
Regards,
Brian.