Str.replace only replacing first instance

RTFM!

Your function “replace” in Javascript is only ONCE without global modifier.
See JavaScript String replace() Method

Example with global modifier in Kantu:

{
  "Name": "test-replace",
  "CreationDate": "2019-10-30",
  "Commands": [
    {
      "Command": "store",
      "Target": "Screen%20Shot%202019-10-28%20at%204.32.19%20PM.png",
      "Value": "t"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var str = ${t}; return str.replace(/%20/g,\" \");",
      "Value": "result"
    },
    {
      "Command": "echo",
      "Target": "${result}",
      "Value": ""
    }
  ]
}
1 Like