How to use str.find() function in python -


what trying achieve want allow user input website google.com , goo.gl only. this, sample code in python console this:

testing find() function in console

the returned result false correct because url meets criteria containing goo.gl. went on testing few more options url https://google.gl/lozxye, find() function return true because not meet criteria containing words 'google.com' or 'goo.gl'.

my problem if assign variable url value below expected return true find() function above because not contain word 'goo.gl' @ all, yet return false.

test find function in console

what wrong happening? how can validate url case above result expected?

thanks.

that line

url = 'https://goo.glab/lozxye' 

does indeed contain 'goo.gl', not want because followed ab in url, changes top-level domain.

one way around not search goo.gl //goo.gl/. works in examples gave, , prevents both following , preceding characters change top-level domain. makes line

url.find('//google.com/') == -1 , url.find('//goo.gl/') == -1 

remember line above works in interactive console. use in program put in if line or expression, such as

if url.find('//google.com/') == -1 , url.find('//goo.gl/') == -1: 

or

expr = url.find('//google.com/') == -1 , url.find('//goo.gl/') == -1 

or (more interactive line)

print(url.find('//google.com/') == -1 , url.find('//goo.gl/') == -1) 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -