replaceRegexCallback

replaceRegexCallback ( object longString , object regexSearch , closure callback ) : string

Replace all occurences of regexSearch in longString by a value returned by callback.

Example


result = replaceRegexCallback("toto titi tata" , /(?si)[aeiou]/, {found->
console("I am working on "+found)
if(equals(found, "a")) return "***"
else return "--"
})
console(result)
/*
-> I am working on o
-> I am working on o
-> I am working on i
-> I am working on i
-> I am working on a
-> I am working on a
-> t--t-- t--t-- t***t***
*/


See also

replace
replaceRegex

Parameters

longString

Text in which the replacement will be performed. This text is then returned with @regexSearch replaced by @replace

regexSearch

Regular expression used to find the corresponding pattern in @longString. This pattern will then be processed by @callback.

callback

A function with an argument. The function must return the replacement text and its argument will be the value of what was found by the regular expression.