by RegexNinja » Fri Apr 24, 2020 2:35 am
Hi.. I just play around with-it in the match, & when something works.. Heck, I just go with it, lol.
Just kidding, if you need help modding anything, just let us know..
Here's something that groups everything independently, so you can edit the replacement as needed.
Note: This regex does not mandate any spaces, or even the occurence of HH MM SS.
However, if they exist, it does match them (in case you ever need to rearrange them).
Regex Match/Replace:
^(.* )*([0-3]\d)-([01]\d-)((?:19|20)\d\d)( [12]\d [0-5]\d [0-5]\d)*(.*)$
\1\4-\3\2\5\6
Replacement Notes:
\1 = Everything before DD (if it exists, otherwise \1 in replacement has no effect)
\2 = DD (note how the - was not grouped)
\3 = MM-
\4 = YYYY
\5 = HH MM SS (if it exists, otherwise \5 has no effect)
\6 = Everything after SS (if it exist, otherwise \6 has no effect)
To mandate either Group1 or Group5, just remove its following * in the match.
If you need help strengthening or relaxing the match, just post back with details.
Results: (for \1\4-\3\2\5\6)
19-05-2019 -------------------------> 2019-05-19
Begin 19-05-2003 End -------------> Begin 2003-05-19 End
Begin 19-05-1998 12 59 59 End --> Begin 1998-05-19 12 59 59 End