mossman mossman - 1 year ago 117
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.

Answer Source
var replaced = $("body").html().replace(/\[.*\]/g,'');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download