JScript, replace all occurrences & symbol list for replacement

Hello,
This is continuation of this drama Passing file paths: FORCE quotes? - #7 by TrialUserSoFar

TLDR.
I'm creating commandline, which executes PS1 file, which passes all user selected files into python with parameters ( cmd /s /c $py_script $element ). Quite a mess I know. :smiley:

So last thing was done - updated DO script, which added additional 'quotes' around supplied path, to help solve problems with bad characters and spaces.
Constructed string looks like this:
powershell D:\v1.ps1 '"D:\TEST_FILES\path\3178.zip"'

And this quote fix broke execution in certain cases.
Now when path itself (file or folder) contains quote ' it needs an backtick symbol ` as mentioned in old topic.
But to make it work, you need to remove additional quotes around.
Result is this:
powershell D:\v1.ps1 "D:\TEST_FILES\path\31``'78.zip"
two symbols because couldn't figure it out how to escape it properly with forum syntax.

I'm find symbols, and replace these with tick added.
str = String(eSel.item().RealPath).replace(/\'/, '``\'')

  1. This method replaced fist found item, how I can replace all occurrences?
    Chat GPT offered to create another function which will replace values, but two functions for single buttons is something new for me.

  2. What syntax would be, if I would like to create list of symbols, with their replacement counterparts?

replace(/!/g, "")
/g is necessary to replace all occurrences.

and to create list, without implementing additional function:

`inputString = inputString.replace(/!/g, "")
                         .replace(/\?/g, "")
                         .replace(/'/g, "")
                         .replace(/\./g, "")
                         .replace(/@/g, "at");`