RegExMatch statement not working. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
royals33
Posts: 4
Joined: 09 Jun 2021, 18:16

RegExMatch statement not working.

09 Jun 2021, 18:37

Below is an excerpt of a script that I've created. I'm getting a list of the controls from an application, parsing through each control in the list and doing a RegExMatch to store the target control in a variable.

The RegExMatch statement is not working any way I try it. From my tests, it appears to have a problem with the periods. If I reduce the pattern to just "WindowsForms10", I get a match. However, if the first period and any number of characters to the right of it are included in the pattern, it fails to find a match. As shown, the periods are escaped. Can anyone point out a problem with the syntax and\or the reason I'm not getting a match?

Code: Select all

WinGet, vCtlList, ControlList, Interaction Desktop
			Loop, Parse, vCtlList, `n
			{
			vCtlClassNN := A_LoopField
			RegExMatch(vCtlClassNN, "^WindowsForms10.SysListView32\.app\.0\.267e1d0*ad1(1|2)$",sInteractionCtl)
			}
[Mod edit: [code][/code] tags added.]
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: RegExMatch statement not working.

09 Jun 2021, 19:16

Try this

Code: Select all

RegExMatch(vCtlClassNN, "^WindowsForms10\.SysListView32\\.app\\.0\\.267e1d0\*ad1(1|2)$",sInteractionCtl)
:wave: There is always more than one way to solve a problem. ;)
royals33
Posts: 4
Joined: 09 Jun 2021, 18:16

Re: RegExMatch statement not working.

09 Jun 2021, 19:40

Tried it, but still no match. Because you suggested an additional backslash, I should clarify that the string for the ClassNN that I'm trying to match actually looks like this

WindowsForms10.SysListView32.app.0.267e1d0_r8_ad11
User avatar
boiler
Posts: 17209
Joined: 21 Dec 2014, 02:44

Re: RegExMatch statement not working.

09 Jun 2021, 19:43

What are you not showing from your code? Because if that is all that is inside the loop, you would only be capturing what is matched (or not) on the last iteration of the loop. If you only display the match after you exit the loop, it would only be the result of that last iteration. Can you show the list of control names?
royals33
Posts: 4
Joined: 09 Jun 2021, 18:16

Re: RegExMatch statement not working.

09 Jun 2021, 20:12

Thanks for responding. The complete list of controls being returned is as follows:

WindowsForms10.Window.8.app.0.267e1d0_r8_ad11
WindowsForms10.Window.8.app.0.267e1d0_r8_ad12
WindowsForms10.Window.8.app.0.267e1d0_r8_ad13
WindowsForms10.Window.8.app.0.267e1d0_r8_ad14
WindowsForms10.SysListView32.app.0.267e1d0_r8_ad11
SysHeader321
WindowsForms10.Window.8.app.0.267e1d0_r8_ad15

I'm attempting to match on the 5th entry. RegExMatch is being used because the Class ("r8" portion) and the NN ("ad11") can change, with the latter sometimes being 12.

What I posted is all of the relevant code for what I'm trying to accomplish with this portion of the logic. I understand your point about only getting the last iteration. I thought of that as a possibility, but wasn't certain. I'm still fairly new to AHK and using a Loop for the first time with this script, so I tried to testing to see if I was getting results in the proper way but couldn't positively confirm. I appreciate any suggestions you can offer.
Attachments
image.png
image.png (331.65 KiB) Viewed 553 times
User avatar
boiler
Posts: 17209
Joined: 21 Dec 2014, 02:44

Re: RegExMatch statement not working.  Topic is solved

09 Jun 2021, 20:33

Try this:

Code: Select all

vCtlList =
(
WindowsForms10.Window.8.app.0.267e1d0_r8_ad11
WindowsForms10.Window.8.app.0.267e1d0_r8_ad12
WindowsForms10.Window.8.app.0.267e1d0_r8_ad13
WindowsForms10.Window.8.app.0.267e1d0_r8_ad14
WindowsForms10.SysListView32.app.0.267e1d0_r8_ad11
SysHeader321
WindowsForms10.Window.8.app.0.267e1d0_r8_ad15
)

Loop, Parse, vCtlList, `n
	if RegExMatch(A_LoopField, "WindowsForms10\.SysListView32\.app\.0\.267e1d0_\w+_ad1[12]", sInteractionCtl)
		break
MsgBox, % sInteractionCtl ? sInteractionCtl : "Not found"
Last edited by boiler on 09 Jun 2021, 20:34, edited 1 time in total.
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: RegExMatch statement not working.

09 Jun 2021, 20:33

try testing in here
https://regexr.com/5vm8l
:wave: There is always more than one way to solve a problem. ;)
User avatar
boiler
Posts: 17209
Joined: 21 Dec 2014, 02:44

Re: RegExMatch statement not working.

09 Jun 2021, 20:40

Your list of controls shows the problem with your original script. Sure enough, it was because you had a control at the end that was similar to the one you wanted to match (up to a point), and your script reported only on the last one. As I suggested could be the case, it matches the last item in the list only up to the point where it starts to deviate. So it found a match with the last time only when your pattern allowed for it. You need to break the loop after it finds the match so that it's reporting on the proper item in the list when you use the full match pattern.
royals33
Posts: 4
Joined: 09 Jun 2021, 18:16

Re: RegExMatch statement not working.

09 Jun 2021, 20:54

Thanks, boiler! With your code, it's doing exactly what I need!!! :superhappy:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 182 guests