From: Shajith CT Date: 2004-07-04T21:41:08+09:00 Subject: Re: Regular expression question Hiya! Use this: str.gsub!(/\{b\}(.*?)\{\/b\}/, '\1') Note the '?' in the regular expression: to make the match non-greedy. Which in English means that it will match till the first "{/b}", and not till the last possible one, which is the default case for some reason. Which is why your regex was matching the longest possible match of ... in the string. See http://www.regular-expressions.info/repeat.html (Parent site's a pretty good regex reference) -CT On Sun, 4 Jul 2004 21:22:43 +0900, 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 > >