Jump to content

Regular Expressions


Recommended Posts

Does Autoit v3 work with regular expression character classes? I couln't find much useage or examples in Autoit for them.

I was trying to do something really simple in which I only wanted to proceed if the window title didn't have something in it.

When the first window comes up it has this title:

ServiceCenter 5.1.5 Express - [Login]

Then different users would log in and the next display would come up with a special code for each user.

The following is the the title of the display that would next come up (the bracketed part is different for each user).

The first part of the title is the same as the above.

ServiceCenter 5.1.5 Express - [XZMRCP]

So all I wanted to do was to wait until the display didn't have

[Lo in it.

WinWaitActive("[REGEXPTITLE: \[[^L][^o]]","",120)

How can I make character classes work in Autoit?

Thanks

Link to comment
Share on other sites

  • Moderators

Try this:

Opt("WinTitleMatchMode", 4)
WinWaitActive("[REGEXPTITLE:ServiceCenter \d+\.\d*\.*\d* Express - \[(?!Login).*?\]]", 120)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Does Autoit v3 work with regular expression character classes? I couln't find much useage or examples in Autoit for them.

I was trying to do something really simple in which I only wanted to proceed if the window title didn't have something in it.

When the first window comes up it has this title:

ServiceCenter 5.1.5 Express - [Login]

Then different users would log in and the next display would come up with a special code for each user.

The following is the the title of the display that would next come up (the bracketed part is different for each user).

The first part of the title is the same as the above.

ServiceCenter 5.1.5 Express - [XZMRCP]

So all I wanted to do was to wait until the display didn't have

[Lo in it.

WinWaitActive("[REGEXPTITLE: \[[^L][^o]]","",120)

How can I make character classes work in Autoit?

Thanks

#include <GUIConstants.au3>
$X = GUICreate("[REGEXPTITLE: \[[^L][^o]]")  
$Button2 = GUICtrlCreateButton ( "WinWaitActive White Notepad",  150, 50 ,200,30)
$Button1 = GUICtrlCreateButton ( "WinWaitActive White out ",  200, 90 ,150,30)
GUISetState ()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
        exit
    Case $msg = $Button2
    Run("Notepad.exe", "", @SW_MAXIMIZE)
    WinWaitActive("Untitled - Notepad","",10000000)
    If WinActive("Untitled - Notepad") Then
    MsgBox(0, "", "WinWaitActive ===> [REGEXPTITLE: \[[^L][^o]]")
    WinWaitActive($X,"",10000000) 
    MsgBox(0, "", "Active ===> [REGEXPTITLE: \[[^L][^o]]")
    endif 
Case $msg = $Button1
    If WinActive($X) then WinClose($X)
    EndSelect
wend
Edited by wolf9228

صرح السماء كان هنا

 

Link to comment
Share on other sites

  • Moderators

#include <GUIConstants.au3>
$g = GUICreate("[REGEXPTITLE: \[[^L][^o]]")  
$Button2 = GUICtrlCreateButton ( "WinWaitActive White Notepad",  150, 50 ,200,30)
$Button1 = GUICtrlCreateButton ( "WinWaitActive White out ",  200, 90 ,150,30)
GUISetState ()
$X = WinGetHandle ($g,"")
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
        exit
    Case $msg = $Button2
    Run("Notepad.exe", "", @SW_MAXIMIZE)
    WinWaitActive("Untitled - Notepad","",10000000)
    If WinActive("Untitled - Notepad") Then
    MsgBox(0, "", "WinWaitActive ===> [REGEXPTITLE: \[[^L][^o]]")
    WinWaitActive($X,"",10000000) 
    MsgBox(0, "", "Active ===> [REGEXPTITLE: \[[^L][^o]]")
    endif 
Case $msg = $Button1
    If WinActive($X) then WinClose($X)
    EndSelect
wend
How does this show how to use Regular Expressions?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

How does this show how to use Regular Expressions?

#include <Array.au3>
$X = GUICreate("[REGEXPTITLE: \[[^L][^o]]")  
$Button2 = GUICtrlCreateButton ( "WinWaitActive White Notepad",  150, 50 ,200,30)
GUISetState ()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
        exit
    Case $msg = $Button2
    Run("Notepad.exe", "", @SW_MAXIMIZE)
    $var = WinList()
    _ArrayDisplay($var, "_ArrayDisplay() Test")
    For $i = 1 to $var[0][0]
    if $var[$i][0] = "[REGEXPTITLE: \[[^L][^o]]" then $X2 = $var[$i][1]
    next 
    WinWaitActive("Untitled - Notepad","",10000000)
    If WinActive("Untitled - Notepad") Then
    MsgBox(0, "", "WinWaitActive ===> [REGEXPTITLE: \[[^L][^o]]")
    WinWaitActive($X2,"",10000000) 
    MsgBox(0, "", "Active ===> [REGEXPTITLE: \[[^L][^o]]")
    endif 
    EndSelect
wend
Edited by wolf9228

صرح السماء كان هنا

 

Link to comment
Share on other sites

Try this:

Opt("WinTitleMatchMode", 4)
WinWaitActive("[REGEXPTITLE:ServiceCenter \d+\.\d*\.*\d* Express - \[(?!Login).*?\]]", 120)
That expression is exactly what I want. I tried it in a regex tool called RegexBuddy and it reacts to the second title only, like I want.

However, for some reason using WinWaitActive like you showed wrongly reacts to both titles in Autoit.

I noticed the Autoit Help file doesn't mention negative lookaheads (?! Could that be why that doesn't seem to work or am I still doing something wrong?

I understand now the need for Opt("WinTitleMatchMode", 4) in order to use the REGEXPTITLE

Also I added the blank text area so I could use the 120 timeout as such:

WinWaitActive("[REGEXPTITLE:ServiceCenter \d+\.\d*\.*\d* Express - \[(?!Login).*?\]]","", 120)

Thank you very much for your help and expertise. I'm impressed how quick you came up with this. Would you have any other ideas for me?

Link to comment
Share on other sites

  • Moderators

Are you using Opt("WinTitleMatchMode", 4) before the win* function calls?

As I have no way of testing this for you... I believe they kept it backwards compatible with the older versions, so please try the following and see if it works:

Opt("WinTitleMatchMode", 4)
WinWaitActive("regexp=ServiceCenter \d+\.\d*\.*\d* Express - \[(?!Login).*?\]", 120)
Let us know if it worked.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Thank you SmOke_N.

With what you gave me I figured out how to do this. I learned a lot on this. It looks like Autoit doesn't recognize character classes. I also learned that sometimes you need to force the display to have the focus again. That was the actual problem I had when I used your examples. When I cause the script to run the application, it would lose focus and wait forever. That's why it didn't seem to work.

Here's my finished script. What it does is start a special application that has to be logged into and then every 10 minutes it refreshes it. The reason I wanted to do this is because the application would always time out after 15 minutes and I would have to restart it again. This script eliminates that problem.

Here's what I came up with that might be helpful to others:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.8.1
 Author: Allen
 Date: 10/3/2007
 Purpose:  Cause the Peregrine application to refresh every 10 minutes during the daytime
 
 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
MsgBox(64,"Peregrine Refresh Display","When Peregrine comes up, logon and it will select the proper display"" button",120)

; Bring up the logon display
run("C:\Program Files\Peregrine\ServiceCenter 5.1.5\RUN\scguiw32.exe","C:\Program Files\Peregrine\ServiceCenter 5.1.5\RUN" )

; Title of display will be:  ServiceCenter 5.1.5 Express - [Login]
; Force focus on this display
WinActivate("ServiceCenter")

; set to advanced mode so it can use regular expressions.
Opt("WinTitleMatchMode", 4)     

; after the person logs on and hits enter, wait for next display
; the display title will slightly different for each person:  ServiceCenter 5.1.5 Express - [XZMRCP]
; so you have to wait for the title that doesn't have login
WinWaitActive("[REGEXPTITLE:ServiceCenter \d+\.\d*\.*\d* Express - \[(?!Login).*?\]]","",30)

; cause the display to select the incidents display
Send("{TAB 2}{ENTER}")

; now the display will have the title: Service Center 5.1.5 Express - [Incidents in inbox: Incidents by Assignment Group]
; change the rest to Mode 2 - Matches any substring in the title
Opt("WinTitleMatchMode", 2) 

; Wait for new display to come up
WinWaitActive("Incidents","",10)

; every 10 minutes send commands to cause the display to refresh
while 1
    if @HOUR < 18 then  ;quit after 6:00 pm

    ; make sure the "incidents" display is still running - no one has closed it
        if WinActivate("Incidents")=1 then
        ; force the focus on this display
            WinActivate("Incidents")

        ; commands to refresh the display
            Send("!p")
            Send("RR")
            Send("{ENTER}")
        Else
        ; close down if the application is no longer running
            ExitLoop
        endif
    Else
    ; after 6:00 pm close the application and stop script
        WinClose("Service Center 5.1.5 Express - [Incidents in inbox: Incidents by Assignment Group]")
        ExitLoop
    EndIf
    Sleep(600000)  ;10 min

wend
MsgBox(1,"Finished","Peregrine is done",2)
Edited by JusGellin
Link to comment
Share on other sites

  • Moderators

Autoit's regular expressions are using the pcre engine, if you take a look into that, not only will you see many opportunities of being able to use RegExp's (as there are a ton of examples of how to extract data from strings out there on this engine), but you'll also see that it does allow class use.

If PCRE does allow class use, then AutoIt should as well (Unless Jon broke something while adding the source code, but that's unlikely). Things that are broken from using the RegExp's would more than likely be broken from the PCRE side of things.

The issue with your assumption on classes being broken, is a result of not understanding them, I say this because of how you tried to use them in your fist example.

In your case, you didn't really just want to exclude any "L" or any "o", but classing it like you did (if done properly) would have done that. So you wouldn't have always ended up with the correct output as you were hoping you would get or that you got with my example of just making sure that Login (the entire word) was not included in that string you were trying to manipulate.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

#include <GUIConstants.au3>
GUICreate("[REGEXPTITLE: \[[^L][^o]]")  
$Button2 = GUICtrlCreateButton ( "WinWaitActive White Notepad",  150, 50 ,200,30)
GUISetState ()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
        exit
    Case $msg = $Button2
     Run("Notepad.exe", "", @SW_MAXIMIZE)
    _WinWaitActive("Untitled - Notepad",300000)
    If WinActive("Untitled - Notepad") Then
    _WinWaitActive("[REGEXPTITLE: \[[^L][^o]]",300000)
    MsgBox(0, "", "WinWaitActive ===> [REGEXPTITLE: \[[^L][^o]]")
    endif 
    EndSelect
wend

Func _WinWaitActive($title ,$Time)
$begin = TimerInit()
While 1
if WinGetTitle("") = $title or TimerDiff($begin) = $Time or TimerDiff($begin) > $Time then ExitLoop
wend 
EndFunc

Edited by wolf9228

صرح السماء كان هنا

 

Link to comment
Share on other sites

  • Moderators

#include <GUIConstants.au3>
GUICreate("[REGEXPTITLE: \[[^L][^o]]")  
$Button2 = GUICtrlCreateButton ( "WinWaitActive White Notepad",  150, 50 ,200,30)
GUISetState ()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
        exit
    Case $msg = $Button2
     Run("Notepad.exe", "", @SW_MAXIMIZE)
    _WinWaitActive("Untitled - Notepad",300000)
    If WinActive("Untitled - Notepad") Then
    _WinWaitActive("[REGEXPTITLE: \[[^L][^o]]",300000)
    MsgBox(0, "", "WinWaitActive ===> [REGEXPTITLE: \[[^L][^o]]")
    endif 
    EndSelect
wend

Func _WinWaitActive($title ,$Time)
$begin = TimerInit()
While 1
if WinGetTitle("") = $title or TimerDiff($begin) = $Time or TimerDiff($begin) > $Time then ExitLoop
wend 
EndFunc
I see what the code is doing, but have absolutely no idea what in the .... you are trying to prove with this code... Did you post it in the wrong thread?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Autoit's regular expressions are using the pcre engine, if you take a look into that, not only will you see many opportunities of being able to use RegExp's (as there are a ton of examples of how to extract data from strings out there on this engine), but you'll also see that it does allow class use.

If PCRE does allow class use, then AutoIt should as well (Unless Jon broke something while adding the source code, but that's unlikely). Things that are broken from using the RegExp's would more than likely be broken from the PCRE side of things.

The issue with your assumption on classes being broken, is a result of not understanding them, I say this because of how you tried to use them in your fist example.

In your case, you didn't really just want to exclude any "L" or any "o", but classing it like you did (if done properly) would have done that. So you wouldn't have always ended up with the correct output as you were hoping you would get or that you got with my example of just making sure that Login (the entire word) was not included in that string you were trying to manipulate.

No doubt I am a rookie on this yet, but I'm gaining more understanding. I believe I do understand how my first code wouldn't have worked. I'll probaly play more with regexp because they certainly can do a lot.

Thanks for your comments.

Link to comment
Share on other sites

I see what the code is doing, but have absolutely no idea what in the .... you are trying to prove with this code... Did you post it in the wrong thread?

#include <GUIConstants.au3>
GUICreate("[REGEXPTITLE:ServiceCenter \d+\.\d*\.*\d* Express - \[(?!Login).*?\]]")  
$Button2 = GUICtrlCreateButton ( "WinWaitActive White Notepad",  150, 50 ,200,30)
GUISetState ()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
        exit
    Case $msg = $Button2
     Run("Notepad.exe", "", @SW_MAXIMIZE)
    WinWaitActive("Untitled - Notepad","",9000)
    If WinActive("Untitled - Notepad") Then
    WinWaitActive("[REGEXPTITLE:ServiceCenter \d+\.\d*\.*\d* Express - \[(?!Login).*?\]]","",9000)
    MsgBox(0, "", "WinWaitActive ===> [REGEXPTITLE:ServiceCenter \d+\.\d*\.*\d* Express - \[(?!Login).*?\]]")
    endif 
    EndSelect
wend

There is a difference between These two codes command WinWaitActive In the first code is not working

Because there are some character in title prevent WinWaitActive

The solution used Handle instead the title

Or use the Func _WinWaitActive

I think now understood the meaning of the difference between the two codes

#include <GUIConstants.au3>
GUICreate("[REGEXPTITLE: \[[^L][^o]]")  
$Button2 = GUICtrlCreateButton ( "WinWaitActive White Notepad",  150, 50 ,200,30)
GUISetState ()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
        exit
    Case $msg = $Button2
     Run("Notepad.exe", "", @SW_MAXIMIZE)
    _WinWaitActive("Untitled - Notepad",300000)
    If WinActive("Untitled - Notepad") Then
    _WinWaitActive("[REGEXPTITLE: \[[^L][^o]]",300000)
    MsgBox(0, "", "WinWaitActive ===> [REGEXPTITLE: \[[^L][^o]]")
    endif 
    EndSelect
wend

Func _WinWaitActive($title ,$Time)
$begin = TimerInit()
While 1
if WinGetTitle("") = $title or TimerDiff($begin) = $Time or TimerDiff($begin) > $Time then ExitLoop
wend 
EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

Link to comment
Share on other sites

  • Moderators

This is good if you "know" which handle you are supposed to be using :).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • 1 year later...

Here is the code that I wrote for peregrines scguiw32 or scguiw32.exe

In short, it winactivates the peregrine window, sets its transparency to see through or 0, sets focus to it, grabs the current resolution, moves it off screen, sends the options key stroke, sends the refresh key stroke, moves it back to the original location, minimizes it and sets its transparency back to full view.

Hopefully this helps someone, it's working for me so far, the only problem I'm having is that it shows a tiny flash of the refresh menu commands on the upper right hand side of the monitor, that you can't seem to get rid of if you move it off screen, and it does something similar if you don't move it? It's no big deal, but it'd be nice to remove it

#include <GUIConstantsEx.au3>
#include <Timers.au3>
#include <Array.au3>

Opt("WinTitleMatchMode", 1)
Opt("SendKeyDelay", 50)

While 1

If ProcessExists('scguiw32.exe') Then
    
    If _Timer_GetIdleTime () <= "5000" Then
        Sleep(2000)
        
    Else
    
    WinSetTrans ("ServiceCenter", "Incident Queue:", 0)
    WinActivate("ServiceCenter", "Incident Queue:") 
    WinWaitActive("ServiceCenter ")
    WinSetState("ServiceCenter - ","",@SW_RESTORE)

    sleep(250)
    
                $winposition = WinGetPos("ServiceCenter", "Incident Queue:")

                $array = _ArrayToString($winposition, @CRLF, 0)


                $array2 = StringSplit($array, @CRLF)

                $originalXaxis = $array2[1]
                $originalYaxis = $array2[3]

                WinMove("ServiceCenter", "Incident Queue:", 2700, 102)

    Sleep(1000)
            
    ControlSend("ServiceCenter ", "", "xSC4550child05", "!P")
    
    ControlSend("ServiceCenter ", "Incident Queue: ", "xSC4550child05", "r")
    
    sleep(250)
    WinMove("ServiceCenter", "Incident Queue:", $originalXaxis, $originalYaxis)
    Sleep(250)
    WinSetState("ServiceCenter - ","",@SW_MINIMIZE)
    
    WinSetTrans ("ServiceCenter", "Incident Queue:", 255 )
    
        
    Sleep(540000)

    EndIf

Else
    
    Sleep(15000)
    
EndIf

WEnd
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...