In this solution, the goal is to extract specific patterns from a given string using a combination of split and match functions. The approach taken here focuses on identifying whitespace, followed by a letter enclosed in parentheses, and another whitespace. This method ensures accuracy even when dealing with complex parenthesis usage.
var str = 'a) first sentence without fixed length b) second phrase c) bla bla bla';
var re = /(?=\s\w\)\s)/g;
var myArray = str.split(re);
var text;
var parenIndex;
for (var i = 0, il = myArray.length; i < il; i++) {
text = myArray[i];
parenIndex = text.indexOf(')');
myArray[i] = [text.substring(0, parenIndex - 1), text.substring(parenIndex + 1)];
}
Another alternative, though less reliable, assumes that every ')' acts as a delimiter for splitting the string.
var str = 'a) first sentence without fixed length b) second phrase c) bla bla bla';
var re = /(?=\w\))|\)/g;
var myArray = str.split(re);
var newArray = new Array(myArray.length / 2);
for (var i = 0, il = myArray.length; i < il; i += 2) {
newArray[i / 2] = [myArray[i], myArray[i + 1]];
}