JSFiddle - React, Tailwind, and code Playground

by Jerry

JavaScript

var str=" , this,  is a ,,, test string , , to find regex,,in js.  , ";
res = str.replace(/^[, ]+|[, ]+$|[, ]+/g, " ").trim();
alert("{" + res+ "}");