I have a set of data that includes dated notes, all concatenated, as in the example below. Assume the date always comes at the beginning of its note. I'd like to split these into individual notes. I've used a positive lookahead so I can keep the delimiter (the date).
Here's what I'm doing:
const notes = "[3/28- A note. 3/25- Another note. 3/24- More text. 10/19- further notes. [10/18- Some more text.]"
const pattern = /(?=\d{1,2}\/\d{1,2}[- ]+)/g
console.log(notes.split(pattern))
and the result is
[ '[',
'3/28- A note. ',
'3/25- Another note. ',
'3/24- More text. ',
'1',
'0/19- further notes. [',
'1',
'0/18- Some more text.]' ]
The pattern \d{1,2} matches both 10/19 and 0/19 so it splits before both of those.
Instead I'd like to have
[ '[',
'3/28- A note. ',
'3/25- Another note. ',
'3/24- More text. ',
'10/19- further notes. [',
'10/18- Some more text.]' ]
(I can handle the extraneous brackets later.)
How can I accomplish this split with regex or any other technique?