From: Andrew Stewart Date: 2007-03-26T20:40:20+09:00 Subject: Re: Knocking Lines Out Of A Multiline String On 23 Mar 2007, at 21:29, Rick DeNatale wrote: > On 3/23/07, Brian Candler wrote: >> On Sat, Mar 24, 2007 at 03:39:42AM +0900, Rick DeNatale wrote: >> > On 3/22/07, Robert Klemme wrote: >> > >> > >Bullshit: just use select: >> > > >> > > >> "foo\nbar\n".select {|l| /^f/ =~ l} >> > >=> ["foo\n"] >> > >> > Or, since he's really trying to exclude lines which include /usr/ >> local/lib: >> > >> > str.reject {|s| Regexp.new("/usr/local/lib").match(s)} That's neat. I should have realised that enumberable's methods come into play with a multiline string. No need to mess about with \n characters -- let Ruby handle those. >> Why does nobody seem to anchor regexps? > > Well, the OP said "I would like to remove lines matching > /usr/local/lib from the multiline string:", no mention of at the start > of a line. > > I did actually consider pointing out that he might have meant at the > beginning of each line, but he didn't so I didn't. And you were right -- the '/usr/local/lib' sequence isn't at the start of the line. (Though the part between the start of the line and this sequence is predictable and could be worked into the regexp.) For those interested, the context of the problem was filtering stack traces produced under autotest: http://blog.airbladesoftware.com/2007/3/22/filtering-autotest-s-output Thanks for all the help. I greatly appreciate it. Regards, Andy Stewart