‘(*MARK:NAME)’ for RegEx Match.Mark Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
boiler
Posts: 17328
Joined: 21 Dec 2014, 02:44

Re: ‘(*MARK:NAME)’ for RegEx Match.Mark

06 Sep 2023, 11:40

Micromegas wrote: I also agree that the condition that the whole string must match reduces the usefulness of the "Mark" feature.
I don’t believe that’s the case. As I mentioned above, I believe it’s only set when there is an error in executing it, not when it successfully executes but finds no match.

Micromegas wrote: Different question: Since we're discussing v.1.1, should we move the question to the board for that?
Yes, I’ll move it since it seems the v2 code is no longer being pursued.

Yes.
User avatar
andymbody
Posts: 968
Joined: 02 Jul 2017, 23:47

Re: ‘(*MARK:NAME)’ for RegEx Match.Mark

06 Sep 2023, 12:05

For clarification:

Is the goal to find the first failed position, and return everything to the left that succeeded (discarding everything to the right of the failure)?

Or is it to find all successful matches in a string, yet using only a single RegExMatch call?

Or a combo of both?

I know nothing about callouts but this may be helpful in your situation.

callouts

Andy
User avatar
andymbody
Posts: 968
Joined: 02 Jul 2017, 23:47

Re: ‘(*MARK:NAME)’ for RegEx Match.Mark  Topic is solved

06 Sep 2023, 18:52

What about something like this?

Code: Select all

Haystack := "<a hello> <b world> <x !> rest of string" 

iPos := 0
while (iPos := RegExMatch(Haystack, "<(.*?)>(.*)(?C" . A_Index . ":Callout)", m, iPos+1))
	dontWorry = beHappy = :)

ExitApp
Callout(m, callNum, fPos, hStack, needle)
{
	; inspect m1, m2, callNum, fPos to determine what to do with each find
	; also have access to all substrings to fine tune positions, etc
    MsgBox % "m=[" . m . "]`nm1=[" . m1 . "]`nm2=[" m2 . "]`nnum := " . callNum . "`npos := " . fPos
    return 0
}

Of course the function steps can be done within the while loop instead if desired (in this case). But it demonstrates the callout functionality to a small degree. The callout feature can be used similar to the MARK feature, but I don't think it has the disadvantage of preventing further matches after the first fail (based on initial tests). I plan to test further to see what is possible. It's a cool trick and I will play with it more in the future.

Andy
User avatar
Micromegas
Posts: 260
Joined: 28 Apr 2015, 23:02
Location: Germany

Re: ‘(*MARK:NAME)’ for RegEx Match.Mark

07 Sep 2023, 03:32

Nice! Thanks for both the idea and the implementation, which is better than what i came up with. (I tried to generate the needle with a loop, and relied on the RegExMatch to do the loop. That might be a bit more efficient, but the return value confused me; i didn't get just one call per callout, as your code does.) Plus, despite my concern about efficiency, it is very fast: ΔA_TickCount was always 0, so that it should work fast enough in the real-life situation.

BTW, i had also spent some time on getting a reply to boiler's statement of 8:40 am about the usefulness. The little i found on the web about that (the only use case was here) seems to indicate that few people use it. I had a hunch that AHK acts differently from Perl here, but haven't completed that investigation, and see no reason to continue with that now.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: CoffeeChaton, Google [Bot], mikeyww, peter_ahk and 130 guests