I have a string that is composed of different elements and I need to separate them at another tag in the string.
I used .split() and .pop() which worked great if there is only one element.
function getText(fullText, type) {
var partial = fullText.split('*' + type + '*').pop().split('*/' + type + '*')[0] || 'unknown';
return partial;
}
var str = "*a*Substring A*/a**b*Substring B*/b**c*Substring C*/c*"
getText(str, a) // returns 'Substring A'
However, I have now encountered multiple elements and in this case it only returns the last element.
var str = "*a*Substring A*/a**b*Substring B1*/b**b*Substring B2*/b*"
getText(str, b) // returns 'Substring B2'
How do I get an array with all the substrings between those tags?