dontpanic couldn't you nest your replacement codes in characters that are illegal in urls, characters that the urlencode function changes.
for example:
I don't think that the brackets would be used or can be used in urls, but I could be wrong.
That way you don't have to worry about parsing through the urls or a hrefs.
Also take a look at the functions_bbcodeparse.php might give you some ideas.
Regards,
g-force2k2