0

I have such a word written within single quotes:

'Macy's'

I need to escape apostrophe(or single quote if used instead) in the word. The regex that I have escape all single quotes in the word. I detect word inside single quotes and try to escape apostrophe(single quote) but all quotes are escaped:

if (word.match(/'(.*?)'/g)) {
   return `'${item.replace(/'/g, "\\'")}'`;
 }

so output is '\'Macys\'' but I need it to be 'Macy\'s'

anubhava
  • 761,203
  • 64
  • 569
  • 643
rick1
  • 946
  • 3
  • 15
  • 31

0 Answers0