I have a string containing a pattern and trying to split this value by space, preserve any spaces inside groups with curly brackets and also preserve the spaces.
Unfortunately my spaces are getting filtered out in the process as well. Is there a way I can preserve them in the process?
var val = "{dimension} {equals,does not equal,contains,does not contain} {value}";
var re = /\s*(\{[a-zA-Z0-9]+\})\s*/g;
var split = val.split(re).filter(Boolean);
console.log('split',split);
Current output:["{dimension}", "{equals,does not equal,contains,does not contain}", "{value}"]
Expected output: ["{dimension}", " ", "{equals,does not equal,contains,does not contain}", " ", "{value}"]