From: Mark Probert Date: 2003-01-11T05:13:34+09:00 Subject: regexp question Hi, again, Rubyists. Below is code that does multiple substitutions on a block of text, using a recursive call to a regexp. The output is like: s1 = {\aa TEXT:} It is {\bb amazing} what a {\xx regexp} can do s2 = TEXT: It is amazing what a regexp can do The trouble is I am getting the following warning (repeated 3 times) warning: string pattern instead of regexp; metacharacters no longer effective when I run the code. The warning comes from the line in the code that reads s = str.sub(match[0], ssub) This expression works (no warnings) outside the function. Any ideas as to why this is happening and how I can get around the warning? BTW, is the a better way of doing this task? Regards, -mark. ---< code >---- def rformat(rfmt,str) fmt = rfmt.slice(-2, 2) # take the last 2 characters only s = '' case fmt when "aa" then s = "#{str}" when "bb" then s = "#{str}" else s = "<#{fmt}>#{str}" end return s end $re = Regexp.compile(/(\{\\[a-z]+)\s([^\}]*)(\})/) def rexp(str) match = $re.match(str) return str if match.nil? ssub = rformat(match[1], match[2]) s = str.sub(match[0], ssub) rexp(s) # recurse to find more patterns end s1 = '{\aa TEXT:} It is {\bb amazing} what a {\xx regexp} can do' puts "s1 = #{s1}" s2 = rexp(s1) puts "s2 = #{s2}"