0

Possible Duplicate:
Python - Check If Word Is In A String.

i have a string which is a url e.g.

my_url = "http://mysite.com/somefolder/somefile"

I want check if "somefolder" is in the my_url file

how do I do that?

0

2 Answers 2

5

Are you looking for this?

if "/somefolder/" in my_url:
    #whatever
Sign up to request clarification or add additional context in comments.

Comments

0

Use:

print 'somefolder' in my_url

OR

print my_url.index('somefolder')

3 Comments

Warning: the second one raises a ValueError if it's not there.
And, print(my_url.find('somefolder') != -1)
Sure, thanx - i simply gave several variants, regex also can be used to find particular word(or pattern) in text

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.