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
  • 57,289
  • 29
  • 176
  • 237
Arpita
  • 1,386
  • 1
  • 15
  • 35

1 Answers1

2

Use regex with g flag:

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

MDN: String.prototype.replace.

VisioN
  • 143,310
  • 32
  • 282
  • 281