JSFiddle - React, Tailwind, and code Playground

by grammar

JavaScript

var testStrings = ["feature/NA-1234", "bug/MRM-321", "exploratory/PM-456"],
    re = /(\w{2,5})\-[0-9]+/ig,
    i = 0, l = testStrings.length;


// The RegEx should match every string inside `testArray`, but because of the `g`
// flag on it, the RegEx instance retains state. As a result of this, when
// iterating over the array of strings, the RegEx fails to match the second entry.
// It is successful in matching the third entry, because a failed match resets the 
// `lastIndex` property on the RegEx to 0.
for(i; i < l; i++) {
    var result = re.exec(testStrings[i]);
    console.log(result);
    console.log(re.lastIndex);
}