From: mitchell Date: 2006-06-03T11:31:19+09:00 Subject: Re: Pattern Matching Question Dave Burt 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. > > I'm not sure exactly what you're trying to do, but is this close? > > s = "{ hello \\} there }" > a = s.scan(/ \{ (( \\ \} | [^}] )*) \} /x).map {|match| match[0].strip } > a[0].gsub!("\\}", "}") > p a[0] #=> "hello } there" > > Cheers, > Dave Cool! I didn't think about the | option. That's quite ingenius. Thanks :) -- Posted via http://www.ruby-forum.com/.