From: "F. Senault" Date: 2009-05-20T02:05:09+09:00 Subject: Re: Problem with Regular Expression Le 19 mai � 18:54, Mario Ruiz a �crit : > I'm replacing a string using: > xmlString.gsub!(/:#{tagName}>#{oldValue}<\//i,":" + tagName + ">" + > value + " > It works perfectly but... if oldValue contains the character +, it > doesn't work. > > Do you know how to solve this? When you interpolate strings into a regexp, the special chars are taken as part of the regexp (meaning your '+' means one or more of the expression before). If you want to match literals, use Regexp.escape : xmlString.gsub!(/:#{Regexp.escape(tagName)}>#{Regexp.escape(oldValue)}<\//i ... >> Regexp.escape("abc+") => "abc\\+" >> Regexp.escape("abc[]+") => "abc\\[\\]\\+" Fred -- When your pubic hair's on fire, something's wrong When you think you're the Messiah, something's wrong When you mistake a plane for Venus, something's wrong When your girlfriend's got a penis... (K's Choice, Something's wrong)