From: mitchell Date: 2006-06-03T23:06:06+09:00 Subject: Re: Pattern Matching Question Jeff Pritchard wrote: > mitchell wrote: >> If I had the text "{ hello \\} there }", what regex could I use to get >> "hello } there" back? I'm really stumped on this one. > > Hi Mitchell, > I'm puzzled by the simplicity of your question. Does it tell the whole > story? If so, you could simplify the whole thing down to: > > a, b = input.scan(/\w+/) # find the two words - there are always two > words, right? > output = "#{a} } #{b}" # output the two words with a space brace > space in the middle > > > Or maybe it is always just like you show it, and all you want to do is > remove the '\\' and the outer braces and spaces, in which case it is as > simple as: > > output = input[2..-3].gsub!(%r{\\},'') > > Just trying to suggest that with a pattern matching question one needs a > bit more context in order to know how simple or complicated the matching > needs to be. But then, maybe if you told us you would have to shoot us. > :) > > best, > jp Actually that was just a simple example. The big idea is to be able to escape '}'s in any inputted string. I later figured that replacing any '\}' with some value (such as '}'s hex code) would work, but playing with regex sometimes can be enlightening :) Thanks for the input though. Much appreciated. -- Posted via http://www.ruby-forum.com/.