From: John Johnson Date: 2004-07-05T06:42:23+09:00 Subject: Re: Regular expression question I realize you've gotten what is probably the most correct answer, but here are a couple of alternatives: str.gsub(/\{/, '<'); str.gsub(/\}/, '>'); or better still str.gsub(/\{(.*?)\}/, '<\1>'); Which has the advantage of being a more general case, i.e. it will work on {h1}, {center} or anything else in braces. Regards, JJ On Sunday, July 4, 2004, at 08:22 AM, George Moschovitis wrote: > Hello everyone! > > I have a question regarding regular expressions. Let me explain > with an example. I have the string: > > "{b}Text{/b} kokoko {b}Lalal{/b}" > > and i want to convert it to this string > > "Text kokoko Lalal" > > if I use the following gsub: > > str.gsub!(/\{b\}(.*)\{\/b\}/, '\1') > > I get: > > "Text{/b} kokoko {b}Lalal" > > not what I want. If I use > > str.gsub!(/\{b\}([^\{]*)\{\/b\}/, '\1') > > I get the correct anwser, but i dont like this > regular expression. Does ruby support an equivalent > to the /g option that perl provides? If not is there > a workaround? I would like to use something like: > > str.gsub!(/\{b\}(.*)\{\/b\}/g, '\1') > > Any help will be apreciated! > > George Moschovitis > > -- > http://www.joy.gr >