From: Axel Schmalowsky Date: 2009-07-14T19:01:23+09:00 Subject: Re: a regex that does not contain comma -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Justin Collins wrote: > Sijo Kg wrote: >> Hi >> Could anybody please tell how to write the validates_format_of a >> string(in rails) which is only valid when it does not contain a >> comma.For example >> >> The are valid >> >> hi welcome >> Hello >> h123 kk >> hh gg hh >> >> The are not valid >> >> Hello, >> Hi , world >> Hello,welcome >> >> Thanks in advnce >> Sijo >> > > I believe > > /^[^,]*$/ > > will do what you need, including matching empty strings. rubular.com is > a good place to try out regular expressions. > > -Justin > I'm confused. Trying the regexp /^[^,]*$/ fails with the code below: #! /opt/csw/bin/ruby string = "Hello, world" #regexp = /\w+(?>\s*(?=,))+/ regexp = /^[^,]*$/ if string =~ regexp puts "string contains a comma" else puts "string does not contain a comma" end p string =~ regexp Am I missing sth? - -- 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 iEYEARECAAYFAkpcV28ACgkQsuqpduCyZM0AWACfbKcs4qyFyg0jCQw4zVhvqtOI jIUAoLIYD/CNaIGrE1EaScWMQo/0F/HL =78tH -----END PGP SIGNATURE-----