Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl (http://www.velocityreviews.com/forums/f17-perl.html)
-   -   Regexp: modify $1 within the replace clause? (http://www.velocityreviews.com/forums/t24971-regexp-modify-1-within-the-replace-clause.html)

Yaroslav 04-16-2004 02:41 PM

Regexp: modify $1 within the replace clause?
 
Hi all,

Consider the following trivial example:

$_ =~ s/<matching_expression>/<clause_that_uses_$1>/g;

Is there a way to build such a regular expression, that matches some
string and modifies the match (e.g. $1) before using it in the replace
clause? What if I want to do something with $1 before I use it to
replace something? Is there a way to insert, say, a function of $1
there, rather than $1 itself?

TIA.

~yaroslav

Joe Smith 04-16-2004 07:49 PM

Re: Regexp: modify $1 within the replace clause?
 
Yaroslav wrote:

> $_ =~ s/<matching_expression>/<clause_that_uses_$1>/g;
> Is there a way to insert, say, a function of $1
> there, rather than $1 itself?


Read the docs, looking for e and ee modifiers.
s/(.*)/foo($1)/eeg;
-Joe

nobull@mail.com 04-21-2004 05:07 PM

Re: Regexp: modify $1 within the replace clause?
 
Joe Smith <Joe.Smith@inwap.com> wrote in message news:<NMWfc.5448$yD1.21555@attbi_s54>...
> Yaroslav wrote:
>
> > $_ =~ s/<matching_expression>/<clause_that_uses_$1>/g;
> > Is there a way to insert, say, a function of $1
> > there, rather than $1 itself?

>
> Read the docs, looking for e and ee modifiers.
> s/(.*)/foo($1)/eeg;


Yes, do read the docs. The OP wants /e not /ee

This newsgroup does not exist (see FAQ). Please do not follow-up here
without pointing this out.


All times are GMT. The time now is 10:01 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.