Beginner inquiry:
I'm struggling with manipulating text using JavaScript. Here is the text I want to transform:
"5555 55:55: John: New York
6666 66:66: Jack: Los Angeles"
My desired output after manipulation:
[{ name:"John", address:"New York", number:"5555 55:55"},{ name:"Jack", address:"Los Angeles", number:"6666 66:66"}]
I am unsure how to inform JavaScript about new lines, names indicated by "xxxx:", and addresses immediately following "xxxx:(space)."
Your assistance on this matter would be greatly appreciated. Thank you in advance.
UPDATE
Current text snippet:
var text = "5555 55:55: John: New York \n 6666 66:66: Jack: Los \n Angeles 7777 77:77: Smith: South Park: 3321"
Here is my current code snippet:
var result = text.match(/\d\d\d\d \d\d:\d\d: [a-zA-Z]+: /g)
.map(function (x) {
x = x.split(': ');
return {
number: x[0],
name: x[1],
address: x[2]
};
});
The issue I'm encountering is that my regex pattern is incorrect, and the 'split' function at ': ' fails when handling addresses that contain colons. Any guidance to resolve this would be much appreciated.