Python intercepts and takes out part of the string

高洛峰
Release: 2017-03-01 11:54:15
Original
3948 people have browsed it

The following is obtained by split interception

>>> 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
>>>
Copy after login

The following is obtained by slicing

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

The result is the same as above.

If we find other methods, we will continue to add them.

The above python interception method to extract part of the string is all the content shared by the editor. I hope it can give you a reference, and I also hope that everyone will support the PHP Chinese website.

For more python interception and taking out part of the string related articles, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!