0

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?

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
Caspian
  • 633
  • 1
  • 10
  • 29
  • Possible duplicate of [Splitting on last delimiter in Python string?](https://stackoverflow.com/questions/15012228/splitting-on-last-delimiter-in-python-string) – Aran-Fey Oct 30 '18 at 23:37

2 Answers2

1

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

1
some_string.rfind("/")

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

pawloka
  • 118
  • 6