From: Axel Schmalowsky Date: 2009-07-14T22:08:02+09:00 Subject: Re: a regex that does not contain comma -----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 /,/. > 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 ___________________________________ 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 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkpcgykACgkQsuqpduCyZM042ACg3fdmTo01wS6DS6bT+416JE2/ deEAoMyfbm2wp81cKDtk7wNp9xXgnzcP =dFl8 -----END PGP SIGNATURE-----