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
  • 713,503
  • 59
  • 514
  • 593
rick1
  • 876
  • 2
  • 14
  • 27

0 Answers0