我有几行..
例如:

var line;
line = "INFO  2014-10-08 15:01:17,233 [localhost-startStop-1] Main directory: C:\WORKSPACE";
line = "ERROR 2014-10-08 15:01:16,646 [localhost-startStop-1] Cannot alter it is not a table.";
var headerArray = line.split("\\s", 3);
//headerArray returns array of 1 element "INFO  2014-10-08 15:01:17,233 [localhost-startStop-1] Main directory: C:\WORKSPACE"; don't know why..


但是我只想要{“ INFO”,“ 2014-10-08”,“ 15:01:17,233”},然后{{ERROR“,” 2014-10-08“,” 15:01:16,646“}

最佳答案

您可以在删除其余部分后拆分。

var line = "ERROR 2014-10-08 15:01:16,646 [localhost-startStop-1] Cannot alter it is not a table.";
var arr = line.replace(/\s+/g," ").replace(/\s\[.+$/,"").split(" ");
console.log(arr);

10-07 19:35
查看更多