How to manipulate dates on a text file?
Posted: Fri Jul 28, 2023 3:23 pm
Hi. I want manipulate dates on a text file, according to some rules.
What is the best way, either with regex or any other method.
E.G:
28/07/2023 > 2023/07/28 or 2023/Jul/28 or 2023-Jul-28
2023.07.20 > 28.07.2023 or 2023 Jul 28
2023 Jul, 28 > 2023 07 28 or 2023/07/28
Etc....Etc..
What is the best way, either with regex or any other method.
E.G:
28/07/2023 > 2023/07/28 or 2023/Jul/28 or 2023-Jul-28
2023.07.20 > 28.07.2023 or 2023 Jul 28
2023 Jul, 28 > 2023 07 28 or 2023/07/28
Etc....Etc..
Code: Select all
;If CreateRegularExpression(0, "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)(?=[\s\S](\d+))\s(\d{2}),\s(\d{4})") ;Good
;If CreateRegularExpression(0, "(\d{2}[- /.])(\d{2}[- /.])(\d{4})")
;If CreateRegularExpression(0, "(\d{2}[- /.])(\d{2}[- /.])(\d{4}[- /.])")
If CreateRegularExpression(0, "(\d{4})([- /.]\d{2})([- /.]\d{2})")
;If CreateRegularExpression(0, "((\d{2}[- /.])(\d{2}[- /.])(\d{4})|(\d{4})([- /.]\d{2})([- /.]\d{2}))")
count = CountRegularExpressionGroups(0)
Debug count
Dim expcount.s(count)
If ExamineRegularExpression(0,text$)
While NextRegularExpressionMatch(0)
For x=1 To count
expcount.s(x)=RegularExpressionGroup(0, x)
Debug expcount.s(x) +" :> "+x
Next
Wend
If count=3;count=7
Define Result.s = ReplaceRegularExpression(0,text$, expcount.s(3)+expcount.s(2)+expcount.s(1))
; Define Result.s = ReplaceRegularExpression(0,text$, expcount.s(5)+expcount.s(7)+expcount.s(6))
Debug "Before : "+text$ + " After :"+Result
ElseIf count=4
Define Result.s = ReplaceRegularExpression(0,text$, expcount.s(4)+"-"+expcount.s(3)+"-"+expcount.s(1))
Debug "Before : "+text$ + " After :"+Result
EndIf
EndIf
EndIf