> toulax / gmail.com wrote:
> How can I make a regular expression that will match everything, unless
> it contains a certain string then it will match nothing.
> 
> For instance, let's say it should not match "bar", then:
> 
> "foo" => "foo"
> "bar " => nil
> "foobar" => nil
> 
> Thanks in advance


How about a negative look-ahead like the one used here 
http://www.ruby-forum.com/topic/37609 ?

If the string contains "bar",  the regex matches the rest of the string 
that does contain no further "bar" substring, i.e. /ar.*$/.

ruby -e 'r = /(?!.*bar).*/; puts r.match("foobarxxxfoobarxxx"); puts 
r.match("foorab"); puts r.match("yyybarbar")'

=> arxxx
=> foorab
=> ar

Cheers

verno


-- 
Posted via http://www.ruby-forum.com/.