Page 1 of 1

IP address leading zero padding for sorting

Posted: Tue Dec 09, 2008 10:58 am
by sdunne
I've been searching the forums for the last 15 minutes without sucess so I've decided to post a plea for help.

I need to zero pad ip addresses within a flat text file so I can then sort them correctly. ie 1.20.30.254 becomes 001.020.030.254

Can some kind soul post up a regular expression that will work with Textpad search/replace that to do this ??

Posted: Tue Dec 09, 2008 11:04 am
by ben_josephs
You can't do it in one step in TextPad. Here's a way to do it in two steps:
Find what: \<([0-9])\>
Replace with: 00\1

[X] Regular expression

Replace All
Find what: \<([0-9]{2})\>
Replace with: 0\1

[X] Regular expression

Replace All
These assume you are using Posix regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax

Posted: Tue Dec 09, 2008 11:30 am
by sdunne
Thanks Ben, that's enough to get me started!