From: Brian Candler Date: 2005-04-07T17:05:08+09:00 Subject: Re: Regular expression mismatch ? On Thu, Apr 07, 2005 at 03:47:15PM +0900, Han Holl wrote: > On Apr 6, 2005 4:58 PM, Warren Brown 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.