I need a regular expression that reliably catches any valid url. I'm using preg (Perl-compatible) on PHP. I've done some testing with it and it seems to work perfectly, but I wanted to open this up and see if anyone has any suggestions. I've tried to make it fairly modular (the break-down is below), but for all I know there are special characters I haven't remembered in the query string, etc...

I know there are a ton online, but they're either not preg, or they just didn't work for me. I also wanted to write my own to be sure I thoroughly understood every part of it. Some of the examples had weird combinations, the reasoning for which I didn't understand.

I'm aware that this won't work if my hostname is local - that's okay, I don't need it to. It's also okay if it matches the occasional non-url (within reasonable limits)- I just to make sure it will match every real one.

Optional protocol
1 or more Subdomains ending with a '.'
1 top-level domain (no '.')
Optional port
Optional file-path/query string

Code:
/([a-z]{3,10}:\/\/)?([a-z0-9\-]+\.)+([a-z]{2,6})(:\d+)?[a-z0-9?=$\/\.%#]*/
Any thoughts or suggestions?

edit: I will have the 'i' (case-insensitive) flag turned on