I have a file with following text structure and would like to parse date inside into an array ...
21/5/12 14:23:36: A: XXXX
YYY
ZZZ
21/5/12 14:23:25: B: XXX ZZZ YYY
21/5/12 14:23:25: B: XXX ZZZ YYY
I am using data.match(/[^\r\n]+\d+.*/g) to parse data from file and the result is
arr[0], 21/5/12 14:23:36: A: XXXX
arr[1], 21/5/12 14:23:25: B: XXX ZZZ YYY
arr[2], 21/5/12 14:23:25: B: XXX ZZZ YYY
Some text of the first item has been removed which is not desired.
Is it possible to use regular expression to parse the text like this?
I'm not sure the exact requirement. But if there's empty line between each data item, you can do it like this:
var data ="21/5/12 14:23:36: A: XXXX\r\nYYY\nZZZ\r\n\r\n21/5/12 14:23:25: B: XXX ZZZ YYY\r\n\r\n21/5/12 14:23:25: B: XXX ZZZ YYY";
data.split(/\r\n\r\n/);
Result of this code is:
["21/5/12 14:23:36: A: XXXX
YYY
ZZZ", "21/5/12 14:23:25: B: XXX ZZZ YYY", "21/5/12 14:23:25: B: XXX ZZZ YYY"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With