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!

2 Answers 2

1
([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}) 
Sign up to request clarification or add additional context in comments.

2 Comments

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)?
([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
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

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.