Need help with regex date conversion

I need to split a date with a "-"
Have added in my macro the replace statement $1-$3$4-$6
That works for every month except october. A date like 20191014 is replaced into 2019-1-14 (missing the zero)
How can i correct this so it works for every month? (changed for now to $1-$3$5-$6)

This works for me:

Expression:

(\d{4})(\d{2})(\d{2})

Substitution:

$1-$2-$3

--> On regex101

Obviously this assumes that the number of digits is always 4/2/2.

3 Likes

Thanks @Tom. That works for me also.
Used another search string :\b(\d{4})(0)?([1-9])(\d*?)(0)?([1-9]\d?)\b