python get all the characters in front of or behind the specified characters

Requirements: Get all the characters before or after the contents of a character in the specified character

 

Example:

   URL = https://www.baid/v2/user/login

 

(1) want to get the data v2: v2 / user / login

   print  url[url.rfind('/v2'):]

 

  (2) wants to get the data before / v2: https: //www.baid/

       print  url[0:url.rfind('/v2')]

 

Guess you like

Origin www.cnblogs.com/syw20170419/p/10969191.html