From: Robert Klemme Date: 2004-01-20T18:09:58+09:00 Subject: Re: regex help "Chris Morris" schrieb im Newsbeitrag news:400C31D0.7010902@clabs.org... > I need a re such that: > > ' /* comment */ String s = "***/"; '.gsub(re, "*\\") > > returns: > > ' /* comment *\ String s = "***/"; ' > > I want to find all *\ instances that are not enclosed in double-quotes. > Or is this one of those problems ill-suited for a regex? str.gsub(%r{"[^"]*"|\*/}) {|m| m == '*/' ? '*\\' : m} If you need single quotes as well, take this one: str.gsub(%r{"[^"]*"|'[^']*'|\*/}) {|m| m == '*/' ? '*\\' : m} Note: the order of the different alternatives matters. Regards robert