I need to convert this...
# 4.0.0 - 2016-01-01
- some text without category
# 3.12.0 - 2016-02-01
- Category: some text
# 3.11.4 - 2016-03-01
- Category: some multiple text
- Something: some text
- Anything: more text
...into an (object)array. I don't know how to keep all elements connected to its version.
The result should be look like this (example for last block)
[
{
major: 3,
minor: 11,
patch = 4,
date = '2016-03-01',
entries = [
{ category: 'Category', 'some multiple text' },
{ category: 'Something', 'some text' },
{ category: 'Anything', 'more text' }
]
}
]
As you can see in the first block, in entries the field category is optional.
This is how I try do it:
var lines = text.split('\n');
for(var i = 0;i < lines.length;i++){
var meta = lines[i].split(' ');
var version = meta[1].split('.');
result['major'] = version[0];
result['minor'] = version[1];
result['patch'] = version[2];
result['date'] = meta[3]
}
But this only works for the first line of each block.
JavaScript? Other engines (e.g.PCREin PHP) provide better functionality like\G.