I want to split the following lines into an array in Javascript:
Jun 02 16:45:04 [steveh] [info] test1
Jun 02 16:45:12 [steveh] [info] test2
Jun 02 16:45:12 [steveh] [info] test3
test 3.1
test 3.2
Jun 02 16:45:16 [steveh] [info] test4
I can do this with:
var arr = data.split(/\r?\n/);
Which gets me that:
[
"Jun 02 16:45:04 [steveh] [info] test1",
"Jun 02 16:45:12 [steveh] [info] test2",
"Jun 02 16:45:12 [steveh] [info] test3",
"test 3.1",
"test 3.2",
"Jun 02 16:45:16 [steveh] [info] test4"
]
So far so good, but the problem is, that I want not 6 items in that array, I want just 4 something like this:
[
"Jun 02 16:45:04 [steveh] [info] test1",
"Jun 02 16:45:12 [steveh] [info] test2",
"Jun 02 16:45:12 [steveh] [info] test3
test 3.1
test 3.2",
"Jun 02 16:45:16 [steveh] [info] test4"
]
I played around some time with the js .match()
and .split()
functions, but couldn't figure it out.
Here is as jsbin: http://jsbin.com/icufef/1/edit