On Wed, Jan 23, 2019 at 12:34 AM Michael Orlitzky <m...@gentoo.org> wrote:
> 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. > > Thanks Michael. The input data is constrained in ways I didnt list, so it might be possible to get away with a regex, but I appreciate you highlighting the risk of what sounds like a brittle approach. I am hopeful that one day learning python will make it to the top of my priority list.