I am trying to convert a numbered list into an array of items. This is what I have so far:
let input = `1. This is a text\n where each item can span over multiple lines\n 1.1 this is another item\n 1.2another item\n 2. that I want to\n extract each seperate\n item from\n 3. How can I do that?`;
let regex = /(\d+\.\d+|\d+)\s(.*)/g;
let matches = input.match(regex);
console.log(matches);
This only produces the following output:
"1.1 this is another item"
What I would like is something like this:
"1. This is a text"
"1.1 this is another item"
"1.2another item"
...and so on
Why is it matching only one item out of this string? What am I doing wrong and how can I fix it?