On Fri, Apr 13, 2012 at 2:38 PM, Jozef Rešetár <lists / ruby-forum.com> wrote: > Hi there, > > please help me with my problem. > > you want to create from "?X is parent of ?Y" ===>> "(\w+) is parentf > (\w+)" > > I was trying something like: > > "?X is parent of ?Y".gsub(/\?[A-Z]/) { "(\\\\w+)" } > "?X is parent of ?Y".gsub(/\?[A-Z]/) { "(\\\w+)" } > "?X is parent of ?Y".gsub(/\?[A-Z]/) { "(\\w+)" } > "?X is parent of ?Y".gsub(/\?[A-Z]/) { "(\w+)" } > > but nothing, This works: 1.9.2p290 :001 > s = "?X is parent of ?Y" => "?X is parent of ?Y" 1.9.2p290 :002 > s.gsub(/\?[A-Z]+/, "(\\w+)") => "(\\w+) is parent of (\\w+)" 1.9.2p290 :003 > puts s.gsub(/\?\w+/, "(\\w+)") (\w+) is parent of (\w+) => nil Take note that what IRB returns is the inspect of the string, so you see double backslashes. If you print it, you'll see the unescaped backslash character. Jesus.