On 22.03.2007 15:43, Andrew Stewart wrote:
> What's a (good!) way to remove lines matching a pattern from a multiline 
> string?
> 
> For example, I would like to remove lines matching /usr/local/lib from 
> the multiline string:
> 
>     
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/test_process.rb:382:in 
> `process'
>     
> /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/test_process.rb:353:in 
> `post'
>     test/functional/orders_controller_test.rb:241:in 
> `test_should_handle_errors_on_edit'
> 
> ..to give:
> 
>     test/functional/orders_controller_test.rb:241:in 
> `test_should_handle_errors_on_edit'
> 
> I tried matching the pattern-to-remove with gsub and substituting an 
> empty string, but that leaves me with lots of blank lines and not really 
> any nearer to the answer.

Convert it to an array and select like

 >> "foo\nbar\n".to_a.select {|l| /^f/ =~ l}
=> ["foo\n"]

Kind regards

	robert