0

I wan to replace all occurrence of a string with single quote but with str.replace it only replaces the first occurrence of the script:

"7<singleQuote>1 inche<singleQuote>s"

Code

var data = "7<singleQuote>1 inche<singleQuote>s"
var output = data.replace("<singleQuote>","'")

Output: 7'1 inche<singleQuote>s

I want to replace <singleQuote> with '.

George Stocker
  • 56,270
  • 29
  • 173
  • 234
Arpita
  • 1,344
  • 1
  • 15
  • 34

1 Answers1

2

Use regex with g flag:

var output = data.replace(/<singleQuote>/g, "'");

MDN: String.prototype.replace.

VisioN
  • 138,460
  • 30
  • 271
  • 271