In my example below, I'm using the same RegEx needle, but changing whether RegExMatch or RegExReplace is used. Also, I'm changing whether the return value of the callout function is -1, 0 or 1.
Will RegExMatch/RegExReplace always give the same list of matches, when a return value of -1 or 1 is used?
Using a return value of 1, for both, is interesting for understanding how RegEx works.
Using a return value of 0, with RegExReplace, appears to be the best way to get *useful* results, although the more inclusive list when the return value of 1 is used, might be more useful sometimes.
Code: Select all
;M-1: 65
;M0: 65
;M1: 65,6,5,66,6,6,67,6,7,68,6,8
;R-1: 65
;R0: 65,66,67,68
;R1: 65,6,5,66,6,6,67,6,7,68,6,8
;q:: ;RegExMatch/RegExReplace work differently here
vOutput2 := ""
vList := "M-1,M0,M1,R-1,R0,R1"
Loop, Parse, vList, % ","
{
vMode := A_LoopField
oArray := []
vText := "--65--66--67--68--"
vRet := SubStr(vMode, 2)
if InStr(vMode, "M")
RegExMatch(vText, "(\d+)(?Cf)")
else
RegExReplace(vText, "(\d+)(?Cf)")
vOutput := ""
for vKey, vValue in oArray
vOutput .= vValue ","
vOutput := SubStr(vOutput, 1, -1)
vOutput2 .= ";" vMode ": " vOutput "`r`n"
}
Clipboard := vOutput2
oArray := ""
MsgBox, % "done"
return
f(vMatch)
{
global oArray, vRet
oArray.Push(vMatch)
return vRet
}