>>>>> "T" == Tobias Reif <tobiasreif / pinkjuice.com> writes:

 Well, I don't like golf but

T> w,h = get_new_dimensions

   rep = {}
   rep['width'], rep['height'] = get_new_dimensions

T> HTMLs.each do |html_file_name|
T>    string = open(html_file_name) do |html_file|
T>      html_file.read
T>    end

      string = IO.readlines(html_file_name, nil)[0]

T>    # how to write these in one (gsub) line?
T>    string.gsub! /width="\d+"/, "width=\"#{w}\""
T>    string.gsub! /height="\d+"/, "width=\"#{h}\""

      You really want to replace height with width ?

      string.gsub!(/\b(width|height)="\d+"/) { "width=\"#{rep[$1]}\"" }

      or

      string.gsub!(/\b(width|height)="\d+"/) { "#$1=\"#{rep[$1]}\"" }

      but because html is a stupid format

      string.gsub!(/\b(width|height)=(['"])\d+\\2/) { "#$1=#$2#{rep[$1]}#$2" }

      to handle the case

       width='12' height="24"

      probably you need \s* for the case width = '12'



Guy Decoux