0

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!

Dave
  • 369
  • 2
  • 8
  • 20

2 Answers2

1
([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})
Mariusz Jamro
  • 30,615
  • 24
  • 120
  • 162
kiri
  • 63
  • 1
  • 6
  • That works beatifully to find the dates, thanks for that. I currently have the following \3-\2-\1 to do the replace (this changes the order and separates with a "-". How do I replace the single occurrences (d/m/yyyy) with a correct date format (yyyy-mm-dd)? – Dave Jun 20 '12 at 11:41
  • `([0-9])/([0-9])/([0-9]{4})` and then `0\3-0\2-\1` or `([0-9]{2})/([0-9])/([0-9]{4})` and then \3-0\2-\1 depeding on where month/day has two numbers – kiri Jun 20 '12 at 13:14
0

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
Michał Niklas
  • 53,067
  • 18
  • 70
  • 114
  • Thanks for this, I was hoping for 1 expression to do it all of rme, but that was me being lazy! This works just fine. – Dave Jun 20 '12 at 12:59