From: Carlos Date: 2006-08-03T11:51:37+09:00 Subject: Re: Using gsub to remove embedded newlines in HTML file Wes Gamble wrote: > Wes Gamble wrote: > >>Something like: >> >> @html.scan(/~\^LNK:.*?\^~/mi).each do |link_line| >> new_link_line = link_line.gsub(/[\s\r\n]/, '') >> @html.gsub!(/#{link_line}/mi, new_link_line) >> end > > > This seems to work well: > > @html.scan(/~\^LNK:.*?\^~/mi).each do |link_line| > new_link_line = link_line.gsub(/[\t\r\n]/, '') > @html.gsub!(/#{Regexp.escape(link_line)}/mi, new_link_line) if > link_line != new_link_line > end You can use a block with gsub: @html.gsub!(/~\^LNK:.*?~/mi) { |s| s.gsub /\s/, '' } or something like that. Good luck. --