[v2] Obscure unmatched parantheses in While-Loop Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

[v2] Obscure unmatched parantheses in While-Loop

16 Nov 2017, 06:30

Hi there,

I'm trying to iterate over all matches within a string using RegExMatch within a While-Loop:

Code: Select all

FoundPos := 1
len := 0
str := "aaaa aabb bbbb bbcc cccc ccbb bbbb bbaa aaaa"
pattern := "O)b{4}"

While (FoundPos := RegExMatch(str, pattern, Match, FoundPos + len)) 
{
  MsgBox(Match[0]) ; for AHK V1 use:  MsgBox % Match[0])
  len := Match.len(0)
}
Running this code with AHK 1.1.26.01 everything is OK - running the same code (except the modification for MsgBox) with AHK 2.0.a081 this leds to an error:

Code: Select all

---------------------------
Test2.ahk
---------------------------
Error:  Compile error 22 at offset 1: unmatched parentheses

	Line#
	001: FoundPos := 1
	002: len := 0
	003: str := "aaaa aabb bbbb bbcc cccc ccbb bbbb bbaa aaaa"
	004: pattern := "O)b{4}"
--->	006: While (FoundPos := RegExMatch(str, pattern, Match, FoundPos + len))
	007: {
	008: MsgBox(Match[0])
	009: len := Match.len(0)
	010: }
	011: Exit
	012: Exit
	012: Exit

The current thread will exit.
---------------------------
OK   
---------------------------
Where does the unmatched parantheses error come from?
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Obscure unmatched parantheses in While-Loop  Topic is solved

16 Nov 2017, 06:34

Remove the O option, in v2, match object is default. :wave:
Edit: Similar in v1, if you use an invalid option, say, "_)needle", errorlevel will be set to the same error, conveniently, v2 throws the error instead :thumbup:
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: Obscure unmatched parantheses in While-Loop

16 Nov 2017, 06:47

:oops: .... missed that!

Thanks a lot for the hint!

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Archimede, niCode, pgeugene, Rohwedder and 31 guests