From: Eddie Catflap Date: 2011-07-15T09:37:14+09:00 Subject: Is there a more efficient way to remove data from a string? 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