Before I do this myself I thought I’d ask here and see if there are any quick solutions.
I don’t need the history-lookup, autocomplete, or other fancy features of Chrome’s omnibar; I just need to detect if a string looks like a valid URL (with valid TLDs and scheme/protocol) or ip-address (IPV4 and IPV6).
I’m not sure how to search chrome’s code repository for a look at how they do it. So if you can find that for me that would be an acceptable answer (bonus points if you port it to javascript!).
Tagged as language-agnostic because I don’t care what language it is in [well, please no Ook or LOLCODE]). Javascript will be the final implementation, though.
There’s a regex provided in RFC2396 – Uniform Resource Identifiers (URI): Generic Syntax (see appendix B) :
I don’t see a reason to not use regex in this case, especially if you’re just checking if it’s a URI or if it’s a search.