Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Remove zero padding from excel mangled Ip addresses

by raybies (Chaplain)
on Mar 21, 2012 at 16:50 UTC ( #960813=note: print w/ replies, xml ) Need Help??


in reply to Re: Remove zero padding from excel mangled Ip addresses
in thread Remove zero padding from excel mangled Ip addresses

Just a nitpick, cuz you did tell him to play with it, but notice that CDU01V43 got changed to CDU1V43... that is most likely not an expected behavior. The above regex removes all 0's unless preceded by a number and followed by a number, which means words with 0's in them will be removed as long as there's a digit following them.

So you might want to split on commas and detect an IP address (dotted quartet) prior to running the above regex (which works great on all IPs I tested).


Comment on Re^2: Remove zero padding from excel mangled Ip addresses
Re^3: Remove zero padding from excel mangled Ip addresses
by GrandFather (Cardinal) on Mar 21, 2012 at 22:42 UTC

    or just change the \d to a \w: s/(?<!\w)0+(?=\d)//g;.

    True laziness is hard work

      Beautiful!

      Testing this one, the only possible unexpected output I had was when I had a bareword (not a dotted quartet) that was all numbers with leading 0's.

      input:>

      040.300.000.048,00145,010.030.000.049,CDU00U04V43

      Output:>

      40.300.0.48,145,10.30.0.49,CD00U04V43

      Which I think most of us would agree is acceptable, assuming the second field is a raw integer value, and not intended to be a code that requires leading zeroes preserved. The nice thing is the word (last field) is preserved.

      Nice, anyhow, thanks for sharing your expertise.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2014-10-25 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (143 votes), past polls