JSFiddle - React, Tailwind, and code Playground
JavaScript
var case1 = "stack,flow(2),over(4),temp(0)";
var case2 = "stack(2),flow,over(4),temp(0)";
var case3 = "stack(2),flow(2),over(4),temp(0";
var case4 = "stack(2),flow(2),over(,temp)";
function testCases(str){
//console.log(str.match(new RegExp("\\([^,]+\\)","g")).length);
// console.log(str.split(",").length);
return (str.match(new RegExp("\\([^,]+\\)","g")).length == str.split(",").length)
}
console.log(case1+": "+testCases(case1));
console.log(case2+": "+testCases(case2));
console.log(case3+": "+testCases(case3));
console.log(case4+": "+testCases(case4));