I have some data in a string, for example
const rawData = `1 Jon Doe 3434 535 3 3 353 HI 3535
2 Jane Smith 23 5235 5 5 2352 HELLO 3543
3 Some Guy 4534 35 5345 4 5345 MEOW 4354`
I want to use the .split() method to make each line (starting with the order number to the end of the last value) its own value in an array.
I have tried
rawData.split(/([0-9]+\s+[A-Z][a-z])/g);
the regex finds a number followed by some whitespace then a capital letter and a lower cased letter (the order number until the start of the first name)
this returns
["", "1 Jo", "n Doe 3434 535 3 3 353 HI 3535", "2 Ja", "ne Smith 23 5235 5 5 2352 HELLO 3543", "3 So", "me Guy 4534 35 5345 4 5345 MEOW 4354"]
I would like to have 3 values by splitting the string at the start of the regex. So I would like to end up with:
["1 Jon Doe 3434 535 3 3 353 HI 3535", "2 Jane Smith 23 5235 5 5 2352 HELLO 3543", "3 Some Guy 4534 35 5345 4 5345 MEOW 4354"]
I can think a workaround, using a for loop to join the values in the array after. I'm curious if there is a way to do it on one line. Thanks!
EDIT
I just found out about lookahead in regex, this works:
rawData.split(/\s(?=\d+\s+[A-Z][a-z])/g);