-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

justarandomguy
  • 145
  • 1
  • 13

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
  • 629
  • 3
  • 9
1

There is an easy way, use the $ operator

.replace(/'|,$/g, '')
elrrrrrrr
  • 894
  • 8
  • 15
1

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

Arindam
  • 185
  • 2
  • 14