From: Robert Klemme Date: 2009-11-27T16:15:10+09:00 Subject: Re: Pattern match to fail if two periods in a row On 11/26/2009 09:46 PM, Ralph Shnelvar wrote: >>>> "abc..def" !~ /\.\./ > =>> false > > I don't think that > "abc..def" !~ /\.\./ > is a regular expression. > > /\.\./ > is a regular expression. > > > Basically ... I need something that will work in a Rails validates_format_of > > # Reject if the email address has two periods in a row > validates_format_of :email, > # See http://en.wikipedia.org/wiki/E-mail_address > :with => ????, > :message => 'invalid email format' You could try negative lookahead irb(main):001:0> s=["aaa", "a.", ".a", "a..", "..a"] => ["aaa", "a.", ".a", "a..", "..a"] irb(main):002:0> s.map {|x| [x, /\A(?:.(?!\.\.))*\z/ =~ x]} => [["aaa", 0], ["a.", 0], [".a", 0], ["a..", nil], ["..a", 0]] Or maybe there is an ":without" which uses the negated match? Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/