I have a variable string like such: [Text that changes]:SPACE: where the :SPACE: is actually a normal space. I need to remove the brackets and everything inside, plus the space following.
I have this:
//<![CDATA[
$(window).load(function(){
function stripParenthesis( node ) {
if(node.length) {
node.contents().each(function(index, child) {
if( child.nodeType === 3 ) {
child.nodeValue = child.nodeValue.replace(/\[.*?\]/g, '');
}
else {
stripParenthesis( $(child) );
}
});
}
}
stripParenthesis( $('div#brackets') ); }); //]]>
This manages to remove the brackets and everything inside. But what about the space following? I don’t know how to adjust the following to make it include both the closing bracket and the space following…
.replace(/\[.*?\]/g, '')
Thanks for any help you can provide. Also, this function will hopefully work even if at some point there is no bracket?
enter code hereJust need to add the \s (whitespace char) at the end.test it out here: http://gskinner.com/RegExr/
EDIT — Complete Code: