Adding a 0 before a date

A swapping-ground for Regular Expression syntax

Adding a 0 before a date

Postby TechGUy » Thu Dec 06, 2012 10:51 pm

I have a bunch of files that have Month-Day-Year.

For example:

1-5-09
1-14-10
3-4-10
11-5-12

etc.

For sorting purposes, I need those months with a single digit (like 1) to have a zero before it to make the month a two-digit.

The results I want would be:

01-5-09
01-14-10
03-4-10
11-5-12 (unchanged)

I'm sure there is a way to do this with RegEx, but I can't seem to get it to work without messing up the 11.

Thanks!
TechGUy
 
Posts: 1
Joined: Thu Dec 06, 2012 10:49 pm

Re: Adding a 0 before a date

Postby Stefan » Fri Dec 07, 2012 7:32 am

You could do an second RegEx run, matching leading sing followed by two signs followed by an dash and the rest, and then drop the first match.

-----------------
3-4-10
11-5-12
-----------------
03-4-10
011-5-12

-----------------
(\d)(\d\d-.+)
\2

03-4-10
11-5-12
-----------------

?
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU


Return to Regular Expressions