Caspian
Caspian

Reputation: 703

URL String Manipulation in Python

suppose I have a string:

some_string = 'https://api.github.com/repos/username/repo-name'

How do I move from right to left and stop at the first occurrence of / such that what is returned will be repo-name?

Upvotes: 0

Views: 350

Answers (2)

pawloka
pawloka

Reputation: 118

some_string.rfind("/")

will return the right-most index of a given character.

Upvotes: 1

Ruslan Gustomyasov
Ruslan Gustomyasov

Reputation: 101

you can do some_string.split("/")[-1]

Upvotes: 1

Related Questions