1

So given the string: '"Something's got to go"' What's the proper way to remove only the surrounding single quotes? So the end result should be: "Something's got to go" notice the lack of surrounding single quotes.

I have attempted: replace(/^'|'$/g, '"') but alas this does not do the trick for me.

Expected Result:

The following: '"Something's got to go"'

Should become: "Something's got to go"

cjstehno
  • 13,468
  • 4
  • 44
  • 56
TheWebs
  • 12,470
  • 30
  • 107
  • 211
  • 2
    Does [this question](https://stackoverflow.com/questions/3315053/java-regex-to-remove-start-end-single-quotes-but-leave-inside-quotes) help? It's for Java but the regex is the same – 0mpurdy Aug 02 '17 at 14:56
  • I am really sorry but why do you need regex for this? Just check if they are and remove them c.substring(1, c.length-1); may be I missed smth? – Drag13 Aug 02 '17 at 14:57

1 Answers1

4

The regular expression you provided should work, see the example below:

console.log(
 `'"Something's got to go"'`.replace(/^'|'$/g, '')
)
Craig Ayre
  • 1,133
  • 9
  • 12