My object string as following
var objStr = "{'light': '5', 'color': '2', 'defect': 'Hello Wo'rld'}";
replace single quote in Hello Wo'rld string like this
objStr = objStr.replace(/([\w]\'[\w])/g, "\\'");
result string is (objStr )
"{'light': '5', 'color': '2', 'defect': 'Hello W\'ld'}" // objStr
And then I get the object like this
eval('(' + objStr + ')'); // {light: "5", color: "2", defect: "Hello W'ld"}
where the 'o' and 'r', what problem with my regular expression?
And what if the single quote between two Chinese characters? (regular expression)
Thank you for your kindly help.