Its probably worth a brief background explanation…
First, a regex() will basically tell you whether or not (true or false) a string matches a particular pattern or not. But it wont really tell you explicitly what parts of your original string matched, nor extract portions of the string out for you.
Second, translate() just does character substitution for you. It will replace one character in your your string in situ with another; eg replace all lowercase letters with their UPPERCASE equivalent. But it will likewise not extract portions of the string for you either.
What you probably want to do is parse your custom date string format - ‘DD/MM/YYYY
’ - to extract the day, month and year substrings, and then rearrange these into the correct proscribed format for a XForm date; ie ‘YYYY-MM-DD
’.
If you are assured your original DD, MM, and YYYY substring are always going to be fixed length (ie days and month numbers are zero-padded if they are a single digit) then you know exactly which characters in your original string to pull out, so you can use the substr() function to do this. However, if your day or month number isnt zero-padded - eg you could have “1/6/2021” - then you’ll instead have to use the ‘/’ character delimiter to break your string into its three components, using the substring-before() and substring-after() functions.
There’s a good explanation of both these approaches here: Take a certain part of a QR response with regex - #5 by Xiphware