gpt4 book ai didi

javascript通过空格分割3个元素

转载 作者:行者123 更新时间:2023-12-02 16:54:32 24 4
gpt4 key购买 nike

我有一些台词..例如:

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);

关于javascript通过空格分割3个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26280695/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com