Forum Discussion

jfpelletier's avatar
jfpelletier
Contributor
12 months ago
Solved

Best way to perform multiple search and replace in a string?

Hello all, I sometimes have to do multiple search and replace operations on a string, and I'm wondering if there's a better way than using multiple ".replaceAll()" methods on that string? The patter...
  • koryknick's avatar
    12 months ago

    jfpelletier - Please download the attached zip file and decompress it.  Import the SLP and upload the expr file to the same project via Manager.  Your regular expressions and replacement strings are in the expr file - note the subtle changes required to the regular expression with the XML tags.

    Basically, I'm using the Expression Library to store the regex as an array, then using the Array.reduce() method to spin through that array and process each replacement on the input variable.

    Please note that if the number of replacements is very large and the volume of data is also large, you may see a significant CPU load on your execution node.  Just something to keep in mind if you have a number of other jobs that need to run at the same time as this process.

    Hope this helps!