Answer the question
In order to leave comments, you need to log in
How to distinguish a search query from a website address?
I am making an application in which there is one text field for url and search query (as in Chrome), how to correctly distinguish the first from the second, given that the user can enter url without http:// ?
Answer the question
In order to leave comments, you need to log in
I decided it works fine, on objective-c this regular expression looks like this:
NSString *pattern = @"^(?i)(?:(?:https?|ftp):\\/\\/)?(?:\\S+(?::\\S*)[email protected])?(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))(?::\\d{2,5})?(?:\\/[^\\s]*)?$";
by regular expression.
You can use the list of all first-level domain zones.
Resolve in DNS what the user entered into the string. If sobered up - most likely, some kind of site.
You can make a HEAD request to be sure.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question