replaceRegex

replaceRegex ( object longString , object regexSearch , object replace ) : string

Replace all occurences of regexSearch by replace in longString. Here we use a regular expression to search for the pattern of regexSearch.

Example


console(replaceRegex("<div><h3>hello world</h3></div>", /(?si)<([^<>]+)>/,"€"))
//-> €€hello world€€


//GOAL: REMOVE NUMBERS IN AN URL
string_to_replace = "https://myurl/hi/2390/hello.com"
console(replaceRegex(string_to_replace,/(?si)(https:\/\/myurl\/hi\/)[0-9]*\/(hello\.com)/,'$1'+'$2'))
// -> https://myurl/hi/hello

//GOAL: REMOVE URL THAT HAVE NUMBERS AT A SPECIFIC POSITION
string_to_replace = "this text must be https://myurl/hi/2390/hello.com without any links"
console(replaceRegex(string_to_replace,/(?si)https:\/\/myurl\/hi\/[0-9]*\/hello\.com/,""))
//-> "this text must be without any links"


See also

replace
replaceRegexCallback

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 replaced by @replace.

replace

Text for the replacement. Use $1, $2, etc to take the content of your masks in regexSearch.