JSFiddle - React, Tailwind, and code Playground

HTML

<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>

JavaScript

var bbcode = 'HI[i]iii[i]iii[/i]iii [b]BOld[/b] yahhh [img]url[/img]';
var matches = bbcode.match(/\[[a-z]*\]/g); //get the matches

var tags = _.groupBy(matches, function(val) {
    val = val.substring(1, val.length-1);
    return val;
});

var errors = [];

for (var tag in tags) {
    var regex = '\\\[/' + tag + '\\\]'; 
    if (bbcode.match(regex).length != tags[tag].length) {
        errors.push('Missing a closing [/' + tag + '] tag');
    } 
}

console.log(errors);