Method RegEx():replaceCallback() Foundation
Replaces matches using a callback code block.
:replaceCallback( <cSubject>, <bCallback>, [<lGlobal>] ) --> cString
Modified string with replacements.
Performs search and replace operations where the replacement text is determined by a callback code block. The callback receives the full match information as a parameter and must return a suitable replacement string.
Replace callback
oRegEx := RegEx():create("\d+")
// Double each number
cResult := oRegEx:replaceCallback("10 and 20", ;
{|aMatch| Var2Char(Val(RegEx():getMatchText(aMatch)) * 2)}, .T.)
? cResult // "20 and 40"
oRegEx:destroy()
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.