From: John Sikora Date: 2010-10-04T23:18:09+09:00 Subject: Re: save only first line from string? Adam Prescott wrote: >>>> "a string\nwith multiple\nlines".split(/\n|\r\n/)[0] >> => "a string" > > "a string\nwith multiple\nlines".split(/\r?\n/).first > > I was somewhat amazed to find not the split solution, but the rather > wild (g)sub solutions as the first responses! I, perhaps erroneously, thought that the OP wanted to modify the string. If so, the split method seems somewhat inelegant, perhaps: string = string.split(/\n|\r\n/)[0]. So I posted the sub! way instead. js -- Posted via http://www.ruby-forum.com/.