From: Phrogz Date: 2007-03-27T00:30:06+09:00 Subject: Re: Knocking Lines Out Of A Multiline String On Mar 23, 12:39 pm, "Rick DeNatale" wrote: > str.reject {|s| Regexp.new("/usr/local/lib").match(s)} Note that the above results in Regexp#new being called for each line in the string; not very efficient: require 'Benchmark' s = "foobar" N = 1000000 Benchmark.bmbm{ |x| x.report( 'Regexp.new' ){ N.times{ Regexp.new( "foobar" ) =~ s } } x.report( 'inline literal' ){ N.times{ /foobar/ =~ s } } x.report( 'as variable' ){ r = /foobar/ N.times{ r =~ s } } } #=> Rehearsal -------------------------------------------------- #=> Regexp.new 20.844000 1.875000 22.719000 ( 22.750000) #=> inline literal 0.906000 0.000000 0.906000 ( 0.906000) #=> as variable 1.094000 0.000000 1.094000 ( 1.094000) #=> ---------------------------------------- total: 24.719000sec #=> #=> user system total real #=> Regexp.new 21.234000 1.671000 22.905000 ( 22.922000) #=> inline literal 0.891000 0.000000 0.891000 ( 0.891000) #=> as variable 1.047000 0.000000 1.047000 ( 1.047000) If you just want to avoid having to escape the forward slashes in the literal, you can use the %r notation for a regexp literal. For example: str.reject{ |s| %r{/usr/local/lib} =~ s }