From: Brian Candler Date: 2003-04-27T19:10:53+09:00 Subject: Re: File reading and line continuation with '\' On Sun, Apr 27, 2003 at 09:39:00AM +0900, Jim Freeze wrote: > > cat a > one\ > two > irb(main):001:0> a=File.read("a") > => "one\\\ntwo\n" > irb(main):002:0> b=File.readlines("a") > => ["one\\\n", "two\n"] > > I would like instead: > > f=File.readlines("a") > ["onetwo\n"] I guess the simplest is to read the whole file in and process it by removing backslash-newline sequences: a=File.read("a").gsub!(/\\\n/,'') a=a.split(/\n/) The split also removes the \n from each result line. Use a=a.scan(/.*?\n/) if you want to keep them (although that will miss the last line if the last character of the file is not a newline) You could perhaps also split the string on a regexp which is \n with a look-behind assertion saying that it's not preceeded by a backslash. Personally I consider such things to be an abuse of regexps :-) In any case, that will leave the backslash-newline sequence within the result string, which you didn't want. Also, the Pickaxe book doesn't indicate that Ruby has look-behind assertions (but it does have look-ahead assertions) Regards, Brian.