Porting perl regexp to ruby

I have a perl regexp that strips c++ comments (I have not constructed
this myself, found it here:
http://www.perl.com/doc/FAQs/FAQ/oldfaq-html/Q4.27.html ). However, it
uses the ‘e’ modifier that will take the replacement value and evaluate
it. How do I get similar functionality in ruby?

perl regexp below:
s#//(.)|/*[^]*+([^/][^]*+)/|"(\.|[^"\])"|’(\.|[^’\])’|[^/"’]+#
$1 ? "/
$1 */" : $& #ge;

/Nick

On Aug 8, 2006, at 6:25 AM, [email protected] wrote:

$1 ? “/*$1 */” : $& #ge;

/Nick

Look at the documentation for gsub. Specifically the block form.

e.g.:

string.gsub(/regex/) { |matched_string| code_to_evaluate }

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs