Dave
Dave

Reputation: 387

reformatting a date

I am using notepad++ to do some date conversions but have run into a problem.

I can convert dates of the format dd/mm/yyyy to yyyy-mm-dd

BUT, some dates are in the form d/m/yyyy because there is only 1 digit for the day or month and then my regex fails.

How can I format them all to read dd/mm/yyyy?

I would really appreciate some help!

Upvotes: 0

Views: 269

Answers (2)

kiri
kiri

Reputation: 63

([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})

Upvotes: 1

Michał Niklas
Michał Niklas

Reputation: 54292

Don't know notepad+ version of regex, but maybe this will do the work:

(\d+)/(\d+)/(\d\d\d\d)

\d is digit and can be replaced by [0-9]

+ means one or more and can be replaced with {1,2} which means one or two occurences

If you want to replace day or month adding leading zero then you should do it using simple program. From editor you will have to do it in 3 steps:

  1. replace dd/mm/yyyy as you do it already
  2. replace d/mm/yyyy [^0-9]([0-9])/([0-9]){2}/([0-9]){4} -> \3-\2-0\1
  3. replace dd/m/yyyy ([0-9]){2}/([0-9])/([0-9]){4} -> \3-0\2-\1

Upvotes: 0

Related Questions