From: "Ian M. Asaff" Date: 2011-07-15T09:54:07+09:00 Subject: Re: Is there a more efficient way to remove data from a string? i'd use a regex and the string split method: ruby-1.9.2-p180 :004 > line = "abcXXdef" => "abcXXdef" ruby-1.9.2-p180 :005 > line.split(/XX/).first => "abc" On Thu, Jul 14, 2011 at 8:37 PM, Eddie Catflap wrote: > Hi > > I have a regex as follows > > REG1=Regexp.new=('dodgydata') > > Basically, I need to read a file in line by line, and on each line > that's a match for my regex, remove everything from the point of the > regex to the end of that line. Is there a more efficient way to do it > than what I have at the moment? I have some HUGE files to process, and > many more regex matches to capture.. :-/ > > ARGF.each_line do [L] > > if L.index(REG1) >   a=L.index(REG1) >   b=L.length >   L.slice!(a..b) >   L << "\n"   # Add a newline back to the end of the line > end > > print L > > end > > (As you can see I'm no ruby expert!). I'd like to be able to make this > more efficient, just doesn't seem a very Ruby way to do things.. All > help gratefully accepted! > > Regards > > Eddie > >