In this regex:
let str = "hello 〔world〕,foo、bar。";
str.replace(/(〔(.*?)〕|(、)|(,)|(。))/gi,'<div>$1</div>');
How to exclude these two square brackets "〔" and "〕" from the result ?
In order to get this result:
"hello <div>world</div><div>,</div>foo<div>、</div>bar<div>。</div>"
replacemethod 2 times. One for replacing the unwanted chars with nothing.replaceinstead of calling it twice, i will go forcallbackfunction ofreplaceas we can save extra work