I found this and wonder if it might be a better solution:
http://stackoverflow.com/questions/8916119/php-replace-n-except-where-other-valid-html-tags-appear
I'm just not sure if XPath can handle bbcode tags.