Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Howto strip 42 from comma separated list using s///

by ady (Deacon)
on Dec 16, 2005 at 10:26 UTC ( [id://517200]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Howto strip 42 from comma separated list using s///
in thread Howto strip 42 from comma separated list using s///

Well the regex did do the job in .NET (using $1$3 as replacement) on lists of the indicated type, like:
"42,43" -> "43" "41,42" -> "41" "41,42,43" -> "41,43"
That is: "42,15,42,173,42" will be reduced to "15,173", which was basically what I wanted. And yes, "before,42XX,after" will be reduced to "beforeXX,after", but that was not the kind of data I needed to manipulate in this case.

You can try out .NET regexes by installing the runtime plus a tool like RegexDesigner.

Update
And you're right: the regex by reasonablekeith above does the same, but will leave "before,42XX,after" intact (if that's what you want); His regex is shorter tho', and could be preferred for that reason, -- but it is not forgiving with resp. to whitespace around the numbers, ie. "23,42 ,45, 56,42" will be reduced to "23,42 ,45, 56".

Best regards,
Allan Dystrup

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-03-29 09:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found