Jump to content

Regular Expression wrong?


Go to solution Solved by Andreik,

Recommended Posts

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

image.png.8d448bf872f1b9745d5f32df8035f907.png

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 by kjpolker
added image
Link to comment
Share on other sites

  • Solution

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 by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...