From: Christian Neukirchen Date: 2004-07-05T18:44:02+09:00 Subject: Re: Regular expression question On Mon, 5 Jul 2004 06:42:23 +0900, John Johnson wrote: > I realize you've gotten what is probably the most correct answer, > but here are a couple of alternatives: > > str.gsub(/\{/, '<'); > str.gsub(/\}/, '>'); You would need .gsub! here, but str.tr('{}', '<>') is even better. (BTW, please drop the ;.) > 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. Be careful, this can be used to do XSS attacks. Best thing would be IMHO: str.gsub!(/\{(\w+)\}/, '<\1>') Alternatively, replace \w+ with a list of allowed tags: b|i|strong|em > Regards, > JJ Christian Neukirchen