var parseShortcodes = function(str){
var regex = /\[\S+(?:\s+[^="]+="[^"\]\s]+")+\]/g,
m, obj, result = [];
while ((m = regex.exec(str)) !== null) {
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
m = m[0].slice(1, -1).split(/\s+/);
result.push(m.reduce(function(r, s){
var pair = s.split('=');
r[pair[0]] = +pair[1].slice(1,-1);
return r;
}, {id: m.shift()}));
}
return result;
};
var str = `First shortcode is [fraction num="1" denom="2"] and the second is [square-root content="456"] which we will pass into a function which will return these IDs and all their values in an object like below'`;
console.log(parseShortcodes(str));