kjpolker Posted July 5, 2023 Share Posted July 5, 2023 (edited) I am trying to work with and manage a GUICtrlCreateDate which is super annoying when opting for 12-Hour format due to the AM/PM issues. To alleviate this I was going to just apply a Regular Expression prior to managing the rest in order to strip the AM/PM but I can't get it to work and I am not sure why? \s([ap]m?)$ - Should be the expression (I have tested on RegExr) but it is not doing anything. Is my expression wrong? #include <GUIConstantsEx.au3> #include <DateTimeConstants.au3> GUICreate("test", 200, 100) $time = GUICtrlCreateDate("", 20, 10, 160, 20, $DTS_TIMEFORMAT) GUICtrlSendMsg($time, $DTM_SETFORMATW, 0, "h:mm tt") $button = GUICtrlCreateButton("check", 75, 40, 50, 20) $label = GUICtrlCreateLabel("", 80, 70, 50, 20) GUISetState() While 1 $nMsg = GUIGetMsg Switch $nMsg() Case $GUI_EVENT_CLOSE GUIDelete() Exit Case $button GUICtrlSetData($label, StringRegExpReplace(GUICtrlRead($time), "\s([ap]m?)$", "")) EndSwitch WEnd I know I could run it through StringReplace twice but I don't like that. StringReplace($time, " PM", "") ;Why can't we just use pipes to separate " PM| AM"... StringReplace($time, " AM", "") Edited July 5, 2023 by kjpolker added image Link to comment Share on other sites More sharing options...
Solution Andreik Posted July 5, 2023 Solution Share Posted July 5, 2023 (edited) Because it's case sensitive. (?i)\s[ap]m$ or ( [AP]M)$ And just in case, maybe it's good to check if there is one or more spaces between time and AM|PM. (?i)( +[ap]m)$ Edited July 5, 2023 by Andreik kjpolker 1 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now