try: mySlash = /\//;
I just needed to add g to make the search global.
On another note then, how can I make the following replace global?
I have made a while loop to do this, but would be nice to see to use the global search would've worked.
mySpace = "%20";
while (myFilePath.search("%20")!= -1)
myFilePath = myFilePath.replace (mySpace, " ");
1 person found this helpful
If I'm not mistaken, you only need to do this once:
myFilePath = myFilePath.replace (/%20/g, " ");
(the slash notation, rather than double quotes, instructs JS to use the GREP replace, which does allow the additional 'g'.)
(and I don't think the '%' is special inside GREPs, so it doesn't need a backslash escape.)
(.. which, thinking a bit further, makes the '%' character quite unique )
I feel honoured having the answer come from 2 of the best!