On 1/21/19 9:55 PM, David Haller wrote:

$ printf '0.1.2.3 01.2.3.4 1.2.3.0 1.2.000.3\n' | \
     sed 's/0*\([[:digit:]]\+\)/\1/g'
0.1.2.3 1.2.3.4 1.2.3.0 1.2.0.3


There are actually more than four examples that it needs to work on. And more to the point, this is going to destroy any other numbers it finds in the input. Phone numbers, zip codes, addresses, credit cards numbers, timestamps, etc. will all get clobbered. It takes like 10 lines of python to do this right; it's silly to invest a ton of effort trying to come up with a regex solution that accidentally works.

Reply via email to