-1

I have a data

'abc','def','ghi',

I want to remove the single quote on all character and want to remove only the last comma, example like below

abc,def,ghi

How would i achieve that using regex for javascript?

I tried using this regex

.replace(^\'|,\s*$,"");

But seems like it is only removing the first quote as shown below

abc','def','ghi',

I am not very good in regex, i appreciate any help that i can get. Thanks

justarandom
  • 135
  • 10

3 Answers3

1

try this:

.replace(/\'|,$/g, "");

the ^ at the beggining made the regexp to only match the quote at the beggining of the string, also you have to add the g to keep looking after the first match

izambl
  • 589
  • 2
  • 9
1

There is an easy way, use the $ operator

.replace(/'|,$/g, '')
elrrrrrrr
  • 796
  • 6
  • 15
1

Can you please check replace(/'|(,)$/g," ") and it should work.

Arindam
  • 65
  • 9