OK - I think there may be have and other solutions but I wrote RegExNMatch function that return first N Matches.
Code: Select all
;--------------------------------------------------------------------------------------
;RegExNMatch(Haystack, NeedleRegEx [, OutputVar, Numbers:= 1, StartingPosition:= 1])
; find first Numbers matches of NeedleRegEx in Haystack from StartingPosition
; return numbers of actually found NeedleRegEx
;
RegExNMatch(Haystack, NeedleRegEx, ByRef OutputVar:="", Numbers:= 1, StartingPosition:=1) {
OutputVar:=[] ;create OutputVar object
loop Numbers ;
if StartingPosition:= RegExMatch(Haystack, NeedleRegEx, v, StartingPosition) {
OutputVar.push(v[1])
StartingPosition += v.len(1)
} else break
return OutputVar.length()
} ;------------------------------------------------------------------------------------
I keep variable names and order but Numbers.
Usage
Code: Select all
str:= "Print size = 84.7 x 60.3 cm; 33.33 x 23.74 inches"
if RegExNMatch(str, "(\d*\.\d*)", V, 2) ;extract first 2 floats
loop V.length()
msgBOX(V[A_Index])
Thanks to all.