JSFiddle - React, Tailwind, and code Playground
by DNCTrung
JavaScript
const string = "This is a [test] with space letter outside and [excluded space letter] inside.";
const matches = string.replace(/\s(?!\[.+?\])/g, "_");
console.log(matches);
/* for (const match of matches) {
console.log(match.index);
} */