Page 1 of 1

how to change it to AHK_H V2 from AHK_L

Posted: 06 Oct 2017, 04:05
by xuezhe

Code: Select all

test := RegExMatches("12_567", "\d+")
Msgbox  % test[1] "," test[2] ; --> 12,567 

test := RegExMatches("12_567", "\d(\d+)", 1) ; 取得子匹配 1 的结果
Msgbox % test[1] "," test[2] ; --> 2,67 


RegExMatches(ByRef Haystack, NeedleRegEx, SubPat:="")
{   
	 arr := [], startPos := 1   
	 while ( pos := RegExMatch(Haystack, NeedleRegEx, match, startPos) )
	  {  
	     arr.push(match%SubPat%)    
	     startPos := pos + StrLen(match) 
	  }    
	 return arr.MaxIndex() ? arr : ""
 }
it doesn't works in AHK_H V2 ,but it works well in AHK_L.

Re: how to change it to AHK_H V2 from AHK_L

Posted: 06 Oct 2017, 05:49
by Helgef
Your function doesn't work in either of the latest L and H v2 versions. Single % to force expressions are removed. Regexmatch now outputs match objects by default. Example for your function,

Code: Select all

test := RegExMatches("12_567", "\d+")
Msgbox  test[1] "," test[2] ; --> 12,567 

test := RegExMatches("12_567", "\d(\d+)", 1) ; 取得子匹配 1 的结果
Msgbox test[1] "," test[2] ; --> 2,67 


RegExMatches(ByRef Haystack, NeedleRegEx, SubPat:=0)
{   
	 arr := [], startPos := 1   
	 while ( pos := RegExMatch(Haystack, NeedleRegEx, match, startPos) )
	  {  
	     arr.push(match[SubPat])    
	     startPos := pos + StrLen(match[SubPat]) 
	  }    
	 return arr.MaxIndex() ? arr : ""
}
Cheers.

Re: how to change it to AHK_H V2 from AHK_L

Posted: 06 Oct 2017, 19:16
by xuezhe
thx.