Date RegEx - Padding 0

Advanced Renamer forum
#1 : 06/11-18 23:47
Posts: 11
I have a lot of files with dates contained in their name in format DD-MM-YYYY.

I was able to write a RegEx to convert them to YYYY-MM-DD. (Not an expert in RegEx by a long shot):

Text to be Replaced = (\d\d|\d)-(\d\d)-(\d\d\d\d)
Replace With = \3-\2-\1

Now, as you might have guessed looking at that RegEx, some dates have "day" in single digit (Example: 1-03-2018), and some have two digits (15-07-2018).

How do I make it to that the single digit date is padded with a 0 in the final output? Example:

From = 1-03-2018
To = 2018-03-01

I was hoping to do it in one expression only, rather than make two separate expressions for D-MM-YYYY and DD-MM-YYYY.

06/11-18 23:47 - edited 06/11-18 23:48
#2 : 07/11-18 06:47
David Lee
David Lee
Posts: 43
Reply to #1:

Add a Renumber method before the Replace method.

Number position: 1
Change to: Relative to existing number
Number difference: 0
Zero padding: Manual
Number length: 2

You could instead add the Renumber method after Replace, in which case you would select Number position 3.

You can also simplify your RegEx by using the "+" quantifier, which will match one or more repetitions of the preceding element: (\d+)-(\d+)-(\d+) or even just (.+)-(.+)-(.+)

07/11-18 06:47
#3 : 07/11-18 19:40
Posts: 11
Reply to #2:

Thanks. The Renumber method was perfect. And thanks for the RegEx suggestions too, for streamlining the expression.

07/11-18 19:40