[英]Node separate the lines in data separated by a semi-colon
I have some data that looks like the one below and the end of each line is separated by a semi-colon. 我有一些看起来像下面的数据,每行的末尾用分号分隔。
id=0345 f1() status=1;
id=7645 f2() status=3;
How can I get each line into an array (without the ending semi-colon). 如何将每一行放入数组中(没有结尾的分号)。
I've tried this: 我已经试过了:
var arr = data.split(';');
console.log(arr);
But it didn't work. 但这没有用。
How can I do this? 我怎样才能做到这一点?
You could remove all the ;
您可以删除所有
;
at the end of each line and then split
at \\n
在每行的末尾,然后在
\\n
处split
const str = `id=0345 f1() status=1; id=7645 f2() status=3;` const arr = str.replace(/;$/gm, '').split(/\\n/g) console.log(arr)
Just split on a semicolon and newline: 只需在分号和换行符上分开即可:
const str = `id=0345 f1() status=1; id=7645 f2() status=3;` const arr = str.split(";\\n"); console.log(arr);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.