mossman mossman - 6 months ago 43
HTML Question

Remove square brackets and their contents using jQuery + regexes

Using an example I've found here, I am trying to remove occurrences of text that are surrounded by these

square brackets.

I have many occurrences of
in my html and want to remove the whole thing, including the brackets.

I've tried this but it doesn't work -- nothing is being replaced:

var replaced = $("body").html().replace(/^\[.*\]$/g,'');

I am trying to match the start using
and the end with
and remove the inner content but I am getting nowhere.

var replaced = $("body").html().replace(/\[.*\]/g,'');