date format help

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
srive99
Posts: 30
Joined: Fri Apr 16, 2010 1:45 pm

date format help

Post by srive99 »

Hello All,

I have a date coming to my application and within the application I need to convert date format using regex. Could some one help me.

my input date could be any of following...
this is just an example date

12/12/12
1/12/12
12/1/12
12/12/2012
1/12/2012
12/1/2012

and my desired output should be 12/12/2012 (dd/mm/yy).

For example, if input date is (18/7/12) I will need to convert that to 18/07/2012.

Thanks
ben_josephs
Posts: 2459
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Are dates the only things containing digits in your text?

If so, try the following:

0. Use "Posix" regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
1. Inset a leading zero in front of single digits:
Find what: \<([0-9])\>
Replace with: 0\1

[X] Regular expression

Replace All
2. Insert 20 in front of 2-digit years:
Find what: \<([0-9][0-9]/[0-9][0-9])/([0-9][0-9])\>
Replace with: \1/20\2

[X] Regular expression

Replace All
User avatar
kengrubb
Posts: 324
Joined: Thu Dec 11, 2003 5:23 pm
Location: Olympia, WA, USA

Post by kengrubb »

ben_josephs,

You rock! I can count on learning more about RE and TP from you.
(2[Bb]|[^2].|.[^Bb])

That is the question.
Post Reply