Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
porting perl regexp to ruby
niklasalverup
8/8/2006 10:23:00 AM
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/...
). 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
1 Answer
Logan Capaldo
8/8/2006 12:07:00 PM
0
On Aug 8, 2006, at 6:25 AM, niklasalverup@hotmail.com wrote:
> 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/...
). 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
>
>
Look at the documentation for gsub. Specifically the block form.
e.g.:
string.gsub(/regex/) { |matched_string| code_to_evaluate }
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
porting perl regexp to ruby
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password