If you want to go purely xpath then you could try to fully validate your pattern dd/mm/yyyy
in a few steps:1
=TRANSPOSE(TEXT(FILTERXML("<t><s>"&SUBSTITUTE(A1," ","</s><s>")&"</s></t>","//s[substring(., 3, 1)= '/'][substring(., 6, 1)= '/'][string-length(translate(., '/' , '')) = 8][translate(., '/' , '')*0=0]"),"dd/mm/e"))
"<t><s>"&SUBSTITUTE(A1," ","</s><s>")&"</s></t>"
- Create a valid XML-construct.
//s
- Select s-nodes where:
[substring(., 3, 1)= '/']
- There is a forward slash at the 3rd index;
[substring(., 6, 1)= '/']
- There is a forward slash at the 6th index;
[string-length(translate(., '/' , '')) = 8]
- The remainder of the node when we replace the forward slashes is of length eight.
[translate(., '/' , '')*0=0]
- The remainder of the node when we replace the forward slashes is numeric.
Needless to say that if your string does not hold any other forward slashes but those in the dates you can simplify the above significantly1:
=TRANSPOSE(TEXT(FILTERXML("<t><s>"&SUBSTITUTE(A1," ","</s><s>")&"</s></t>","//s[contains(., '/')]"),"dd/mm/e"))
Notice that if "dd/mm/yyyy" is recognized by Excel as dates, the returned array of simply using //s
would return the numeric equivalent of these dates. If no other numeric values exist in your string you could benefit from that using Microsoft365 functionality1:
=LET(X,FILTERXML("<t><s>"&SUBSTITUTE(A1," ","</s><s>")&"</s></t>","//s"),TRANSPOSE(TEXT(FILTER(X,ISNUMBER(X)),"dd/mm/e")))
1: Note that you can remove the nested TEXT()
function and numberformat your cells to dd/mm/e
too.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…