python intercepts a part of a string

The following is the split interception to obtain

>>> str = 'http://manualfile.s3.amazonaws.com/pdf/gti-chis-1-user-9fb-0-7a05a56f0b91.pdf'
>>> print str.split()
['http://manualfile.s3.amazonaws.com/pdf/gti-chis-1-user-9fb-0-7a05a56f0b91.pdf']
>>> print str.split('/')
['http:', '', 'manualfile.s3.amazonaws.com', 'pdf', 'gti-chis-1-user-9fb-0-7a05a56f0b91.pdf']
>>> print str.split('/')[-1]
gti-chis-1-user-9fb-0-7a05a56f0b91.pdf
>>> print str.split('/')[-1].split('.')[0]
gti-chis-1-user-9fb-0-7a05a56f0b91
>>> 

 

Below is obtained by slicing

 

name = str[str.rfind("/")+1:str.rfind(".")] 

 

Same result as above.

 

If other methods are found, I will continue to add

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324518446&siteId=291194637