David A. Black wrote:
Hi --
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 /,/.
You'd want to use \A and \z, rather than ^ and $ (which delimit lines,
rather than the whole string).
But if you've already tested for /,/, then you should be able just to
have an else clause in your case statement, to cover cases where /,/
didn't match.
David
- --
Freundliche Grüße / Kind regards
Axel Schmalowsky
Platform Engineer
···
On Tue, 14 Jul 2009, Glenn Jackman wrote:
___________________________________
domainfactory GmbH
Oskar-Messter-Str. 33
85737 Ismaning
Germany
Mobil: +49 (0)176 / 10246727
Telefon: +49 (0)89 / 55266-356
Telefax: +49 (0)89 / 55266-222
E-Mail: aschmalowsky@df.eu
Internet: www.df.eu
Registergericht: Amtsgericht München
HRB-Nummer 150294, Geschäftsführer:
Tobia Sara Marburg, Jochen Tuchbreiter