3

My string is like this:

temp="'SE019','SR132','SC123'";

I use a function like:

temp.replace("'","");

But the result will be:

SE019','SR132','SC123'

only the first quote is removed I need all the quotes to be removed

xanatos
  • 109,618
  • 12
  • 197
  • 280
BaN3
  • 435
  • 1
  • 3
  • 16

2 Answers2

8

Use a regex literal with the g (for global, meaning match all occurrences) option.

temp.replace(/'/g,"");

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp.

Trevor Dixon
  • 23,216
  • 12
  • 72
  • 109
0

To remove a reoccurring character or substring you can also use split/join method:

temp.split("'").join("")

It's less obvoius what it does and may be considered premature optimization, but may be marginally faster (or slower :)) http://jsperf.com/regex-split-join

pawel
  • 35,827
  • 7
  • 56
  • 53