Why does this not give the expected results? It seems the PCRE_GetMatchedCaptureNumber function returns the wrong amount of found occurances?
Code:
#Include PCRE_DLL.ahk
PCRE_Init()
testInput =
(
Hello I have a Lot of Words starting Capitalised.
Now I'm trying to find All of them. Will I succeed?
There should be 8 of them...
)
testRE = ([A-Z][a-z])
; Gui
Gui, Add, GroupBox, x6 y15 w460 h120 , Input
Gui, Add, Edit, x16 y35 w440 h90 vInputTxt, %testInput%
Gui, Add, GroupBox, x6 y145 w460 h120 , Regular expression
Gui, Add, Edit, x16 y165 w440 h20 Default vSearchRE, %testRE%
Gui, Add, Edit, x16 y195 w440 h20 vReplaceRE,
Gui, Add, Button, x16 y225 w90 h30 gSearch, Search
Gui, Add, Button, x116 y225 w90 h30 gReplace, Replace
Gui, Add, GroupBox, x6 y275 w460 h120 , Output
Gui, Add, Edit, x16 y295 w440 h90 vOutputTxt,
; Generated using SmartGUI Creator 4.0
Gui, Show, x238 y168 h407 w477, New GUI Window
Return
Search:
GuiControlGet, InputTxt, , InputTxt
If InputTxt =
GuiControl, , InputTxt, %testInput%
GuiControlGet, SearchRE, , SearchRE
If SearchRE =
GuiControl, , SearchRE, %testRE%
; Register Regular expression
hRE := PCRE_RegisterRegExp(SearchRE, #PCRE_MULTILINE)
if (hRE = 0)
PCRE_ShowLastError()
hMatch := PCRE_Match(hRE, InputTxt)
n := PCRE_GetMatchedCaptureNumber(hMatch)
i = 0
toShow =
Loop
{
s%i% := PCRE_GetMatchStr(hMatch, 0)
If ErrorLevel = -1
Break
PCRE_GetMatchVals(hMatch, i, pos%i%, len%i%)
toShow := toShow "`n" s%i% " - " pos%i% " - " len%i%
PCRE_MatchNext(hRE, hMatch)
i++
}
GuiControl, , OutputTxt, % "Found according to PCRE_GetMatchedCaptureNumber: " n "`nFound by looping: " i toShow
Return
Replace:
Return
GuiEscape:
GuiClose:
PCRE_End()
ExitApp