Reputation: 9285
I need a json-string to be used in a regex. Honestly I am a bit confused about all the escaping.. :)
I want to replace "\o/" by something else by regex. The source string should be in a JSON.
This is the JSON-String without escaping:
var emoticons=...
+ '{"img": "party.png","short": "\o/"},'
...
I tried to escape the slash and backslash to meet the regex' need but after that wasn't able to parse the JSON anymore:
var emoticons=...
+ '{"img": "party.png","short": "\\o\/"},'
...
How should the JSON-String look like?
Code:
var smilies = JSON.parse(emoticons);
text.replace(new RegExp(smilies.short,......);
Upvotes: 0
Views: 1227