Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Regex to replace consecutive tokens

by oiskuu (Hermit)
on Oct 18, 2013 at 22:54 UTC ( #1058844=note: print w/replies, xml ) Need Help??


in reply to Regex to replace consecutive tokens

If all values are alphanumeric, you can use this:
$s =~ s/,\B/,0/g;

Update. Here's a rx that handles leading and trailing commas, empty strings:

$s =~ s/(^|,)\K(?![^,])/0/g;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2016-12-06 01:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (96 votes). Check out past polls.