From: Christopher Causer Date: 2008-02-27T00:23:55+09:00 Subject: Multiple substitutions in one pass I have a long document which I am trying to parse. I am coming unstuck trying to speed it up and get all the substitutions out the way quickly. I have a hash array of original and new things to substitute, and it works. However, I'm sure there is a more efficient way of doing things. RegExp has a union method, but that doesn't seem to handle string capture within matches. One final thing is that I would like this sub to throw something if no substitutions are performed on the str. -------------------------------------------------- def makeSubs(str) subCurlyArray={/section%LCURL%(\d+)(.*?)%RCURL%\1/ => "\n"+'---+\2', /subsection%LCURL%(\d+)(.*?)%RCURL%\1/ => "\n"+'---++\2', /subsubsection%LCURL%(\d+)(.*?)%RCURL%\1/ => "\n"+'---+++\2', /emph%LCURL%(\d+)(.*?)%RCURL%\1/ => '\2', /includegraphics\[(.*)\]%LCURL%(\d+)(.*?)%RCURL%\1/ =>'IMAGE ENDIMAGE', /texttt%LCURL%(\d+)(.*?)%RCURL%\1/ => '\2 ', /code%LCURL%(\d+)(.*?)%RCURL%\1/ => '\2', /textbf%LCURL%(\d+)(.*?)%RCURL%\1/ => '*\2*', /textit%LCURL%(\d+)(.*?)%RCURL%\1/ => '_\2_', } subArray.each do |orig, new| str.gsub!(orig, new) else return str end --------------------------------------------------- Thank you -- Posted via http://www.ruby-forum.com/.