I decided to play around with regular expressions to improve my (limited) knowledge and came up with a function to parse a date string into the format of YYYY/MM/DD. Therefore allowing for variations of YYYY.MM.DD or YYYY]MM@DD, since most (not all) of the functions in the Date.au3 UDF accept the format of YYYY/MM/DD. Therefore my question is can the SRE be improved at all? Thanks. #include <Date.au3>
Output(@YEAR & @MON & @MDAY)
Output(@YEAR & '-' & @MON & '-' & @MDAY)
Output(@YEAR & '\' & @MON & '-' & @MDAY)
Output(@YEAR & '/' & @MON & '/' & @MDAY)
Output(@YEAR & '/ ' & @MON & '/ ' & @MDAY & '15:12:08')
; Parse a date string to the format of YYYY/MM/DD as certain formats can use '.' or '-' in certain system locales.
Func _ParseDateString($sDateString)
Return StringRegExpReplace(StringStripWS($sDateString, 8), '(\d{4})\V?(\d{2})\V?(\d{2})(\V*)', '$1/$2/$3 $4') ; Can this be improved in anyway?
EndFunc ;==>_ParseDateString
Func Output($sString)
Return ConsoleWrite('[' & $sString & '] >> ' & _ParseDateString($sString) & @CRLF)
EndFunc ;==>Output