Okay, this is really pretty frusturating. I should have realized it earlier. My bbcode function replaces [link ] tags, which also follow the format of this regular expression. When it replaces it with the HTML <a> tag, the actual URL (which follows the pattern of the regular expression) contained in it is replaced by the regular expression. It's really annoying, and I found a way around it, but it's not ideal. I think I'm going to have to resort to using some search/buffer/replace type method like was originally suggested. Even though this is a lot slower and less efficient, it's really the only methodology I can forsee working in every case.
Here's the regular expression I used (it works great!):
$s[] = "^[\s]+(((ht|f)tp(s?))\:\/\/)(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.([a-z])(\:[0-9]+)*((\/?))(([a-zA-Z0-9\.\,\;\?\'\\\=\/\_\-\#\%\&]+)?)^";
$r[] = '<a href="\0" target="_blank">\0</a>';
Notice the "[\s]+", which indicates some amount of whitespace (space, linebreak, tab, etc) prepending the URL, as long as it's there. This works in most cases, but what if the link is at the beginning of the text or IS the entire text? Yeah, doesn't work in those situations.
Without it, though, the following regular expression causes issues because of the nature it represents:
$s[] = "#\[(link|url)=(((ht|f)tp(s?))\:\/\/)(.*?)](.*?)\[/link\]#si";
$r[] = '<a href="\2\6" target="_blank">\7</a>';
This is a [ link ] [ /link ] tag. It also works fine in isolation, but it also gets replaced with the following after the URL regular expression runs through preg_replace:
[link=<a href="<URL>"><URL></a>]<text>[/link]
There's one possible solution I can think of still retaining the regular expression methodology, but I haven't gotten it to work. That is: If it matches this string and "DISCLUDES" this string. IE it can't begin with url= or link=, which would eliminate my problem with this.
I'm going to try to mess around with a bit of search/buffer methodologies of URL replacing. I'll post with updates.