SetTitleMatchMode Regex + i) option failing Topic is solved

Report problems with documented functionality
User avatar
RaptorX
Posts: 388
Joined: 06 Dec 2014, 14:27
Contact:

SetTitleMatchMode Regex + i) option failing

Post by RaptorX » 06 Apr 2024, 15:05

Hello,

If you try this you will get the expected result if you have an AHK GUI out there.

Code: Select all

SetTitleMatchMode 'Regex'
F1::Msgbox WinExist("ahk_class AutoHotkey.*")

But as soon as you use the case insensitive option it returns 0x0

Code: Select all

SetTitleMatchMode 'Regex'
F1::Msgbox WinExist("i)ahk_class AutoHotkey.*")
The equivalent code for v1 does not have this issue.
Projects:
AHK-ToolKit
User avatar
andymbody
Posts: 949
Joined: 02 Jul 2017, 23:47

Re: SetTitleMatchMode Regex + i) option failing

Post by andymbody » 06 Apr 2024, 16:32

Both v1 and v2 display no match for me when I place the option at the beginning of string. But the following works for me in both versions...
"ahk_class (?i)AutoHotkey.*"

v1.1.37.01
v2.0.11
User avatar
RaptorX
Posts: 388
Joined: 06 Dec 2014, 14:27
Contact:

Re: SetTitleMatchMode Regex + i) option failing

Post by RaptorX » 06 Apr 2024, 17:40

andymbody wrote:
06 Apr 2024, 16:32
Both v1 and v2 display no match for me when I place the option at the beginning of string. But the following works for me in both versions...
"ahk_class (?i)AutoHotkey.*"

v1.1.37.01
v2.0.11
Yes, your suggestion works, interestingly these also work:

Msgbox WinExist("ahk_class i)AutoHotkey.*")
and
Msgbox WinExist("ahk_class (?i)AutoHotkey.*")
and even this one:
Msgbox WinExist("i) ahk_class AutoHotkey.*") ; notice the space after the option

but not this one:
Msgbox WinExist("i)ahk_class AutoHotkey.*")
Projects:
AHK-ToolKit
just me
Posts: 9541
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: SetTitleMatchMode Regex + i) option failing

Post by just me » 07 Apr 2024, 03:36

All is working as documented.

Code: Select all

Msgbox WinExist("i)ahk_class AutoHotkey.*")
This would search for a window title containing "ahk_class AutoHotkey.*". The ahk_ criteria must not be included in regex needles.
neogna2
Posts: 598
Joined: 15 Sep 2016, 15:44

Re: SetTitleMatchMode Regex + i) option failing

Post by neogna2 » 07 Apr 2024, 05:27

I think just me is right, see
https://www.autohotkey.com/docs/v2/lib/SetTitleMatchMode.htm#Parameters
RaptorX wrote:
06 Apr 2024, 17:40
and even this one:
Msgbox WinExist("i) ahk_class AutoHotkey.*") ; notice the space after the option
There i) is ignored but the function finds and returns a Hwnd anyway because the case in AutoHotkey matches the class name case. It returns zero if we change to
Msgbox WinExist("i) ahk_class autohotkey.*")
User avatar
RaptorX
Posts: 388
Joined: 06 Dec 2014, 14:27
Contact:

Re: SetTitleMatchMode Regex + i) option failing

Post by RaptorX » 07 Apr 2024, 10:00

I think im understanding now.

Why doesnt v1 have this issue?
Projects:
AHK-ToolKit
User avatar
andymbody
Posts: 949
Joined: 02 Jul 2017, 23:47

Re: SetTitleMatchMode Regex + i) option failing

Post by andymbody » 07 Apr 2024, 10:17

RaptorX wrote:
07 Apr 2024, 10:00
Why doesnt v1 have this issue?
My tests did show this same behavior in v1. But maybe I tested it wrong?
User avatar
RaptorX
Posts: 388
Joined: 06 Dec 2014, 14:27
Contact:

Re: SetTitleMatchMode Regex + i) option failing

Post by RaptorX » 07 Apr 2024, 12:20

andymbody wrote:
07 Apr 2024, 10:17
RaptorX wrote:
07 Apr 2024, 10:00
Why doesnt v1 have this issue?
My tests did show this same behavior in v1. But maybe I tested it wrong?
Nope you are right, I was the one who didnt perform the test correctly because of the point justme mentioned above. As soon as I changed the casing it stopped matching even with the "i)" option.

I guess my point seems to be that with the current usage of the tool

Code: Select all

"i)ahk_class AutoHotkey.*"
this seemed to be an ambiguous statement to me which now that they explained each part of the title match (ahk_class, ahk_exe) will have its own options so to speak, which is a bit strange as this would be an invalid i)testing ahk_class i)AutoHotkey.* Regex string in any other circumstance. Usually you cant have options like that unless on the second part you have the opening parenthesis like this: i)testing ahk_class (?i)AutoHotkey.*... see my confusion?
Projects:
AHK-ToolKit
User avatar
andymbody
Posts: 949
Joined: 02 Jul 2017, 23:47

Re: SetTitleMatchMode Regex + i) option failing

Post by andymbody » 07 Apr 2024, 12:42

RaptorX wrote:
07 Apr 2024, 12:20
see my confusion?
Yes. I suppose for clarity I will use the standard regex (?i), rather than the AHK option formatting. Because it does indeed look even more strange with the AHK formatting.

Looks like this works for multiple criteria... and is a little easier to read for me.
"(?i)tEsTiNg ahk_class (?i)autoHOTKEY.*"
User avatar
RaptorX
Posts: 388
Joined: 06 Dec 2014, 14:27
Contact:

Re: SetTitleMatchMode Regex + i) option failing

Post by RaptorX » 07 Apr 2024, 20:10

andymbody wrote:
07 Apr 2024, 12:42
RaptorX wrote:
07 Apr 2024, 12:20
see my confusion?
Yes. I suppose for clarity I will use the standard regex (?i), rather than the AHK option formatting. Because it does indeed look even more strange with the AHK formatting.

Looks like this works for multiple criteria... and is a little easier to read for me.
"(?i)tEsTiNg ahk_class (?i)autoHOTKEY.*"
agree, thanks for the clarification.
Projects:
AHK-ToolKit
lexikos
Posts: 9663
Joined: 30 Sep 2013, 04:07
Contact:

Re: SetTitleMatchMode Regex + i) option failing

Post by lexikos » 11 Apr 2024, 21:19

RaptorX wrote:
07 Apr 2024, 12:20
each part of the title match (ahk_class, ahk_exe) will have its own options so to speak, which is a bit strange as this would be an invalid i)testing ahk_class i)AutoHotkey.* Regex string in any other circumstance.
Personally I think your perspective is a bit strange. WinTitle is clearly not a regex string, but a WinTitle string containing one or more criteria. The title and class name values can potentially be regex patterns (plural), but it is obviously not one big pattern across the whole set of criteria, which includes special keywords. Each pattern matches against either the title or the class name, not some combination of e.g. WinGetTitle(hwnd) " ahk_class " WinGetClass(hwnd).

i) in the middle of WinTitle can look odd, but it should remind you that WinTitle is a series of separate patterns and not one big RegEx. If you can be confused by i)A ahk_class B, you can also be confused by (?i)A ahk_class B not applying case sensitivity to B.

As an aside, options can be specified in a non-capturing group to better delineate the effective span of the option; e.g. (?i:A) ahk_class (?i:B).
User avatar
RaptorX
Posts: 388
Joined: 06 Dec 2014, 14:27
Contact:

Re: SetTitleMatchMode Regex + i) option failing

Post by RaptorX » 11 Apr 2024, 22:34

lexikos wrote:
11 Apr 2024, 21:19
Personally I think your perspective is a bit strange. WinTitle is clearly not a regex string, but a WinTitle string containing one or more criteria.
Yes, now that it has been clarified I think the same. I think is a problem of the documentation not being clear enough on that point rather than a syntax problem. It does mention it but as a side note, rather than an important point.

Im not sure how many people use multiple criteria when using SetTitleMatch 'Regex' but to me, using that command looked like it made the whole string being interpreted as a Regex string instead of a series of independent objects.

So, to be clear, Im not advocating for any changes in how this is done. I just got confused and when reading the manual, my confusion was not cleared until someone pointed out the obvious: each ahk_ keyword is a somewhat unrelated search that is grouped in one big string.
Projects:
AHK-ToolKit
lexikos
Posts: 9663
Joined: 30 Sep 2013, 04:07
Contact:

Re: SetTitleMatchMode Regex + i) option failing  Topic is solved

Post by lexikos » 05 May 2024, 20:40

Apparently it has been documented like this (with slight syntax changes) since 2016:
For WinTitle, each component is separate, e.g. in "i)^untitled ahk_class i)^notepad$ ahk_pid " mypid, i)^untitled and i)^notepad$ are separate regex patterns and mypid is always compared numerically (it is not a regex pattern).
Source: SetTitleMatchMode - Syntax & Usage | AutoHotkey v2
Seems sufficiently explicit.
User avatar
RaptorX
Posts: 388
Joined: 06 Dec 2014, 14:27
Contact:

Re: SetTitleMatchMode Regex + i) option failing

Post by RaptorX » 06 May 2024, 11:05

lexikos wrote:
05 May 2024, 20:40
Apparently it has been documented like this (with slight syntax changes) since 2016:
For WinTitle, each component is separate, e.g. in "i)^untitled ahk_class i)^notepad$ ahk_pid " mypid, i)^untitled and i)^notepad$ are separate regex patterns and mypid is always compared numerically (it is not a regex pattern).
Source: SetTitleMatchMode - Syntax & Usage | AutoHotkey v2
Seems sufficiently explicit.
What I meant is that it mentions it as a side note, rather than an important point. In certain commands we get a warning or note that highlights potential pitfalls of a command.

As I mentioned previously, I think I got the idea once I noticed that same text, is just that when you are quickly browsing the documentation you might not see it right away because is not prominent enough and then try to troubleshoot why the thing is not working as intended :lol:
Projects:
AHK-ToolKit
Post Reply

Return to “Bug Reports”