我正试图解开字符串(获取原始\ t字符)。
我一直在尝试所有这些方法:
var s = "my \t string";
var t = "\\t"; // Backslashes are escaped because this is rendered on an <input>
// How do we split the string?
s.split(t); // ["my string"]
s.split(t.substring(1)); // Not working becuase t.substring(1) is just 't'
s.split(t.replace(/\\\\/g, "\\")); // ["my string"]
// Expected result would be:
s.split('\t'); // ["my ", " string"]
// Using JSON.parse works
s.split(JSON.parse('"' + t + '"')); // ["my ", " string"]
JSON.parse是唯一的方法吗?