Reputation: 387
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
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:
dd/mm/yyyy
as you do it alreadyd/mm/yyyy
[^0-9]([0-9])/([0-9]){2}/([0-9]){4}
-> \3-\2-0\1
dd/m/yyyy
([0-9]){2}/([0-9])/([0-9]){4}
-> \3-0\2-\1
Upvotes: 0