Axel Schmalowsky wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > David A. Black wrote: > >> Hi -- >> >> On Tue, 14 Jul 2009, Glenn Jackman wrote: >> >> >>> case string >>> when /,/ then puts "#{string.inspect} contains a comma" >>> when /^[^,]*$/ then puts "#{string.inspect} has no comma" >>> end >>> >> That second regex, on its own, won't tell you the whole story: >> >> string = <<-EOM >> Hi. >> I have, at a minimum, two commas. >> Bye. >> EOM >> >> p "Match!" if /^[^,]*$/.match(string) >> => Match! >> >> > Technically, the regexp above always succeeds (iirc). > Even though the regexp is delimited by ^ and $, > it matches always as along as the string against which the regexp is applied > does not consist of only a single comma ('[^,]* -- match everything > (including nothingness) but a comma). > > So, I guess it's better to simply use /,/. > The OP needed something that would match only if there were no commas. I am not a Rails person, but I looked up the method mentioned by the OP and it is indeed expecting a regex that matches valid input (e.g., no commas) and rejects invalid input (any commas). You are right about the line begin/end, though. If there could be multiple lines in the input, it should use \A and \z instead of ^ and $. I guess I am just too used to parsing things one line at a time :) -Justin