I'm having trouble figuring out two separate issues with a REGEX that I'm using in a BBCode auto-url hotlinking pattern that I have implemented. incomingtext is the variable that holds the user's data (retrieved from the DB). The first replacement is the auto-hotlinking pattern. The 2nd replacement is for HTML image replacements. The 3rd and 4th are BBCode manual hotlinking patterns.

The problems:
1. My negative character class is matching against characters and replacing them with nothingness. I know why it's happening, but I need to make sure that if there are those characters prior to my pattern, that it doesn't match. How can I do this without removing the previous characters? Similarly, if there are NO characters prior to the matching pattern, then the pattern fails.

2. Another developer implemented something like PHP's nl2br (insert a BR tag at any point a newline is discovered). That's nice, but for some reason, when quoting another user (also implemented by another developer), the BR tags are kept within the post. That's not a big deal, the larger issue is that my auto-hotlinking pattern is apparently matching the less than symbol and the letters BR from the BR tag, inserting a newline, and then printing the greater than symbol. (http://igbl.nwcd.net/index.cfm?FuseA...09&iStartRow=1 -- the last post in the forum topic) From looking at my REGEX, I don't see how it can even match a less than symbol...

Help?

My pattern replacement code is below:


Code:
if (FindNoCase("://", incomingtext)){
	incomingtext=reReplaceNoCase(incomingtext, "[^>\'\""\=\]] ?((https?|ftp|telnet)://[\w\d:##@@%%\/\;\$\(\)~_\?\+-\=\\\.&]{2,}\.[\w\d:##@@%%\/\;\$\(\)~_\?\+-\=\\\.&]{2,})","<a href=""\1"">\1</a>","ALL");
	incomingtext=reReplaceNoCase(incomingtext, "\[img\]http://(.*?)\[/img\]", "<img src='http://\1' />", "ALL");
	incomingtext=reReplaceNoCase(incomingtext, "\[url\](.*?)\[/url\]", "<a href=""\1"">\1</a>", "ALL");
	incomingtext=reReplaceNoCase(incomingtext, "\[url=(.*?)\](.*?)\[/url\]", "<a href=""\1"">\2</a>", "ALL");
}