Hey there how do I escape ' and " using javascript regex?
because I want
Annie said, "It's really funny."
to be like,
Annie said, \"It\'s really funny.\"
Hey there how do I escape ' and " using javascript regex?
because I want
Annie said, "It's really funny."
to be like,
Annie said, \"It\'s really funny.\"
Use string.replace.
string.replace(/(['"])/g, "\\$1")
Example:
> var s = 'Annie said, "It\'s really funny."'
undefined
> console.log(s.replace(/(['"])/g, "\\$1"))
Annie said, \"It\'s really funny.\"
Hey there how do I escape ' and " using javascript regex?