RegEx callouts: RegExMatch v. RegExReplace

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

RegEx callouts: RegExMatch v. RegExReplace

26 Jun 2017, 15:58

RegExMatch and RegExReplace work differently during callouts. I'm not sure exactly why this is.

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
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: arczi_87, Green Astronaut, hitman, Lepes, mikeyww, Smile_ and 56 guests