1

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 [sample-text] 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,'');
$("body").html(replaced);

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

1
  • 1
    You want to remove the ^ and $, as they aren't the beginning or ending of the total text or lines. Aug 13, 2012 at 17:56

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.