Regexp: modify $1 within the replace clause?

Y

Yaroslav

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
 
J

Joe Smith

Yaroslav said:
$_ =~ 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
 
N

nobull

Joe Smith said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top