Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Re: Replacing consecutive tokens in 1 pass

by OM_Zen (Scribe)
on Feb 22, 2003 at 23:24 UTC ( #237813=note: print w/ replies, xml ) Need Help??


in reply to Re: Replacing consecutive tokens in 1 pass
in thread Replacing consecutive tokens in 1 pass

Hi ,

Your script gives the output |x|x|foo|bar|x|x|x|x|x|

The post as required needs to retain the 906 and hence , one cannot do a normal "+" search on the digits and also the user string can have a 9[0-9]at any portion of the string like |868969780| , then your scripts turns it to x like this |868x| , and your script is a bit greedy and also changes the pattern to "x" .

Hence we require to have a look_ahead and look_behind positive assertions(here regular width is ok) to have a pattern match of 9[0-9]following a "|" but not including a "|" and followed by a "|" but not including the "|" as the pattern

$str =~ s/(?<=\|)9[0-9](?=\|)/X/g;
This is the extended pattern that shall do it as in my previous post


Comment on Re: Re: Replacing consecutive tokens in 1 pass
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (9)
As of 2015-07-04 09:01 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 (58 votes), past polls