Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: String substitution

by kroach (Pilgrim)
on Sep 20, 2016 at 15:15 UTC ( #1172222=note: print w/replies, xml ) Need Help??


in reply to String substitution

If I understood correctly, you want to replace (nr\d+) with "calc($1);" and multiply other occurences of \d+ by 4. This can be done with a single regex:
$data =~ s/(nr)?(\d+)/$1 ? "calc($1$2);" : $2 * 4/ge;
This will match both nr\d+ and \d+ and then decide how to replace it based on the presence of "nr".

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1172222]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2020-10-20 00:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (208 votes). Check out past polls.

    Notices?