I have 2 kinds of strings coming back from an API. They look as follows:
let string1 = "\n1. foo\n2. bar\n3. foobar"
let string2 = "\n\n1. foo.\n\n2. bar.\n\n3. foobar."
To be clear, string 1 will always have 3 items coming back, string 2 has an unknown number of items coming back. But very similar patterns.
What I want to do is pull out the text only from each item into an array.
So from string1 I want ["foo", "bar", "foobar"]
From string2 I want ["foo.", "bar.", "foobar."]
I'm awful at regex but I somehow stumbled myself into an expression that accomplishes this for both string types, however, it uses regex's lookbehind which I'm trying to avoid as it isn't supported in all browsers:
let regex = /(?<=\. )(.*[a-zA-Z])/g;
let resultArray = str.match(regex);
Would someone be able to help me refactor this regex into something that doesn't use lookbehind?