2008/9/7 Axel Etzold <AEtzold / gmx.de>: > to achieve searching for some text pattern that is not followed by something else, you need > regular expressions with negative lookahead > > http://www.regular-expressions.info/lookaround.html > > As far as I know, this is not supported by Ruby's 1.8.x regexps, Negative lookahead *is* supported by that (and earlier) version. The problem with negative lookahead is that - with the test data given - that the negative lookahead is difficult to get right: irb(main):016:0> %w{foo.jpg foothumb.jpg}.each do |s| irb(main):017:1* p [s, /\A\w+(?!thumb)\.jpg\z/ =~ s] irb(main):018:1> end ["foo.jpg", 0] ["foothumb.jpg", 0] => ["foo.jpg", "foothumb.jpg"] I am not saying that it won't work but off the top of my head I do not have a solution that works. In any case, it's easier to exclude matches outside the regular expression engine. One way would be to make thumb a capturing group and check whether the group is present, like irb(main):022:0> %w{foo.jpg foothumb.jpg}.each do |s| irb(main):023:1* p [s, /\A\w+?(thumb)?\.jpg\z/ =~ s, $1] irb(main):024:1> end ["foo.jpg", 0, nil] ["foothumb.jpg", 0, "thumb"] => ["foo.jpg", "foothumb.jpg"] and use that criterion for exclusion. Now you can meditate on why the negative lookahead did not work. :-) Kind regards robert -- use.inject do |as, often| as.you_can - without end