IP address leading zero padding for sorting

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
sdunne
Posts: 2
Joined: Tue Dec 09, 2008 10:51 am

IP address leading zero padding for sorting

Post 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 ??
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post 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
sdunne
Posts: 2
Joined: Tue Dec 09, 2008 10:51 am

Post by sdunne »

Thanks Ben, that's enough to get me started!
Post Reply