I was trying to split a string based on multiple delimiters by referring How split a string in jquery with multiple strings as separator
Since multiple delimiters I
If you want to split based in multiple regexes and dont want to write a big regex
You could use replace and split.
Like this:
const spliters = [
/(\[products\])/g,
/(\[link\])/g,
/(\[llinks\])/g,
];
let newString = "aa [products] bb [link] [products] cc [llinks] dd";
spliters.forEach(regex => {
newString = newString.replace(regex, match => `æææ${match}æææ`);
});
const mySplit = newString.split(/æææ([^æ]+)æææ/)
console.log(mySplit);
This works very well for my case.