Skip to main content
Known Participant
Sep 5, 2022 8:13 PM UTC
Question

Replace All Occurrences of a Substring in a String

What is the APPIAN's equivalent for  JS String.replaceAll ? 

    3 replies

    Inspiring
    Sep 6, 2022 4:00 AM UTC

    you can use substitute function for this.

    for example: substitute(
    "ACTUAL_TEXT","SUB_STRING","TO_REPLACE_WITH"
    )

    mikes0011
    Brainy
    Sep 6, 2022 1:40 PM UTC

    Appian OOTB substitute() works fine for any basic use cases as DeepakG already mentioned above.  Just chiming in to add, that for more advanced use cases (fuzzy / pattern-matching / etc), you can also use "regexReplaceAll()" found in the Regex plug-in.

    The Expression Guru
    rahata9316
    Inspiring
    Sep 7, 2022 4:20 AM UTC

    If you can check if reduce can give this the desired result also. Somewhere in community I read this last time.

    if(
      count(ri!originalValues) <> count(ri!replacementValues),
      ri!inputText,
    
      reduce(
        fn!substitute,
        ri!inputText,
        merge( ri!originalValues, ri!replacementValues )
      )
    )