Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Replacing matches within string without splitting.

by BrowserUk (Pope)
on Jan 02, 2013 at 06:44 UTC ( #1011213=note: print w/replies, xml ) Need Help??

in reply to Replacing matches within string without splitting.

Use lookahead:

$t = "1,2,3,4\n8,9,10,11\n7,8,9,10,\n12,13,14,15\n";; print $t;; 1,2,3,4 8,9,10,11 7,8,9,10, 12,13,14,15 $t =~ s[(\D|^)(?=\d(?:\D|$))][${1}0]g;; print $t;; 01,02,03,04 08,09,10,11 07,08,09,10, 12,13,14,15

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1011213]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2017-04-28 11:50 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (521 votes). Check out past polls.