* Robert Klemme <bob.news / gmx.net> [Jan, 20 2004 17:30]:
> > str.gsub!(/"[^"\\]*(\\.[^"\\]*)*"|\*\//){ |m| m == '\*' ? '*\\' : m }
> Did you test that?  I'm afraid, it doesn't work:
yes, but i seem to have made a mistake in copying it over for some
reason, the problem is the test, not the regex, it should be

str.gsub!(/"[^"\\]*(\\.[^"\\]*)*"|\*\//){ |m| m == '*/' ? '*\\' : m }
						    ^^

> If you want to allow quotes to be escaped, this one is the way to go:
>
> irb(main):012:0> puts str.gsub(%r{"([^"\\]|\\")*"|\*/}) {|m| m == '*/' ?
> '*\\' : m}
>   /* comment *\  String s = "***/";
well, this isn't really correct, that would only escape quotes and you
wouldn't allow for escaped backslashes in your strings....it is of
course trivial to mend.  do note that my version is a lot faster...see
"Mastering Regular Expressions" by Jeffrey E. F. Friedl on why this is
so.  anyway, thanks for pointing out that something was wrong,
	nikolai

--
::: name: Nikolai Weibull    :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA    :: loc atm: Gothenburg, Sweden    :::
::: page: www.pcppopper.org  :: fun atm: gf,lps,ruby,lisp,war3 :::
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}