0

in php code im using this preg_replace('/[^a-z%0-9.\/_]/i', '', $filename);, May i know how to convert php preg_replace to javascript replace?

I'm convert the code into this filename.replace(/[^a-z%0-9.\/_]/i, ''); in javascript, but the result is different.

$filename = (123).jpg

php result = 123.jpg

javascript result = 123).jpg

mic_test
  • 121
  • 2
  • 13

1 Answers1

0

Use the /g modifier to remove all occurrences:

filename = "(123).jpg";
console.log(filename);
filename = filename.replace(/[^a-z%0-9.\/_]/ig, '');
console.log(filename);
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360