I'm stumped...
http://codepen.io/anon/pen/rjjGEE
Why does the regex javascript string replace work for the string with special characters, but not the object converted to a string?
let regex = /[\t\r\n]/g
var directString = "{'name':{'first':' billy bob ','last':'\n\rjoe\tblow'}}"
console.log(directString.replace(regex, "a"));
//Output: "{'name':{'first':' billy bob ','last':'aajoeablow'}}"
let obj = {
name: {
first: " billy bob ",
last: "\n\rjoe\tblow"
},
}
let objAsString = JSON.stringify(obj);
let stringifiedString = objAsString.replace(regex, "a")
console.log(stringifiedString)
//Output: "{'name':{'first':' billy bob ','last':'\n\rjoe\tblow'}}"
//??? Why isn't \n\r and \t being replaced????
directStringandobjAsStringto the console. You will see that you have two different strings (and I'm not talking about the quotation marks).