I need to split a string where I need to grab three pieces of information from that string, and putting it in array so essentially, the array will always have three thing: [first, second, third], and the second and third item can be blank.
The line will be in the form of "First Second, Id". I need to ignore the extra spaces after each word or before each word.
So the first and second word is distinguished by a space or spaces in between and the second word and Id is distinguished by a comma.
Examples of lines to split:
John Doe, 1234 => result: [John, Doe, 1234]
John [# spaces] Doe,[# spaces] 1234 => result: [John, Doe, 1234]
[# spaces] John [# spaces] Doe [# spaces] , [# spaces] 1234 => result: [John, Doe, 1234]
John , 1234 => result: [John,"",1234]
John => result: [John, "", ""]
I tried using the regex, line.split(/[\s,]+/), but it would only work for case 1.
How to create a regex that includes all these cases?
/[\s,]+/