JSFiddle - React, Tailwind, and code Playground
by bikz92
JavaScript
console.log("hello");
var myStrA = "bs-cat bs-dog bs-yup bs-bob";
var bs_class = myStrA.match(/\S+-(cat|dog|bob)/g);
console.log("matches: " + bs_class);
// among these find out which one it was
// https://stackoverflow.com/questions/494035/how-do-you-use-a-variable-in-a-regular-expression
var bs_main = "(cat|dog|bob)";
var re1 = new RegExp("\\S+-" + bs_main,"g");
var re1_ng = new RegExp("\\S+-" + bs_main);
// get first one it matches
var bs_class_base = myStrA.match(re1_ng);
console.log(" base: " + bs_class_base);
var bs_classB = myStrA.match(re1);
console.log("bs classes: " + bs_classB);
// join together into one string
// now check among these which it is
for (var i in bs_classB) {
console.log("next reg: " + bs_classB[i]);
}
// doesn't take capture classes, if you use global:
// https://stackoverflow.com/questions/38889331/javascript-global-match-with-capturing-groups