The reason there is no noticeable problem on the first call is that
%m.1% in
q := %m.1% doesn't fit in
q's string buffer, so a new buffer is created. But on the second call, there is enough space in the buffer, so its content is just updated. The problem is that
regexreplace didn't make a copy of the buffer so it
sees the update.
Here is an example where there is enough space in the buffer on the first call,
Code: Select all
replace(m, *) {
global q
q := '+++'
}
q := "abc"
w := RegExReplace('123', "2(?Creplace)", q)
msgbox w
You can even change the
haystack from the callout. I do not think it is worth the bother to fix this. In particular, it implies that we need to make copies of the inputs which in ~99.99999% of the time would be a waste. I think it should be sufficient to add a note in the documentation, stating that callout functions should avoid changing the input parameters of
regexreplace (and
regexmatch).
Cheers.