Home > Back-end >  AutoHotKey IfWinExists Not Working With ReGex
AutoHotKey IfWinExists Not Working With ReGex

Time:09-22

I have a window title something like this: ComInstr - Q4NATIONAL-11.21(1).pdf - Google Chrome

I want to use IfWinExist to let me know if that windows exists. I do this:

SetTitleMatchMode Regex

IfWinExist i)\..{3,4} - Google Chrome
{   
  Msgbox Here
}
return

The title of the window will change, but it will always contain a dot and 3 or 4 characters (an extenstion) and then - Google Chrome.

This doesn't work and I don't know why. Any advice?

CodePudding user response:

Okay, not sure why but this works:

SetTitleMatchMode Regex 
regex_match:="\..{3,4} - Google Chrome"
IfWinExist %regex_match%
{

CodePudding user response:

You would need to escape the comma with `,.
Otherwise your arguments to the IfWinExist(docs) command are as follows:

  • WinTitle = i)\..{3
  • WinText = 4} - Google Chrome

So, be sure to escape the comma:
IfWinExist i)\..{3`,4} - Google Chrome


But really, you shouldn't use legacy AHK.
IfWinExist is a deprecated legacy command and should no longer be used.
Use WinExist()(docs) along with the modern if ()(docs) instead.

In modern AHK you don't need to worry about the troubles legacy syntax will bring you here since you're explicitly specifying strings inside "":
if (WinExist("i)\..{3,4} - Google Chrome"))

  • Related