Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Regex to replace consecutive tokens

by oiskuu (Friar)
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;


Comment on Re: Regex to replace consecutive tokens
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2015-07-31 18:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (280 votes), past polls