I have the following script:
$(".Text").contents().each(function () {
$(this).replaceWith($(this).text()
.replace(/\[([^\]]*)\]/g, '<span class="IT_Symbol" style="display:inline;border: 1px solid blue;">$&</span>')
);
});
It finds anything between square brackets and wraps it with a class. The element style is so i can see it working, as this script is triggered by a doubleclick. Currently it finds everything between square brackets including the brackets themselves. If possible, i’d like to remove the brackets, but keep what’s between.
You’re replacing with
$&, which is the whole matched text. If you replace with$1instead, this only matches the first group, which is([^\]]*), and therefore excludes the surrounding brackets.