D
D
deleted-mezhevikin2014-06-07 19:54:38
Android
deleted-mezhevikin, 2014-06-07 19:54:38

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

4 answer(s)
D
deleted-mezhevikin, 2014-06-08
@deleted-mezhevikin

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]*)?$";

B
bahek2462774, 2014-06-07
@bahek2462774

by regular expression.
You can use the list of all first-level domain zones.

L
lnked, 2014-06-07
@lnked

show an example of your search query with a website address

V
Vlad Zhivotnev, 2014-06-08
@inkvizitor68sl

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 question

Ask a Question

731 491 924 answers to any question