I have a list of strings that contain a url plus some other words. The URL looks like this: <a href="https://www.blabla/k20832">
I was wondering if there is a way to tell python to delete everything inside the <>
.
I was using this to delete other words:
list = [w.replace('hello', '') for w in list]
You can use regex.
import re
str = "<a href=\"https://www.blabla/k20832\"> word1 word2"
str2 = re.sub('<a.*?>', ' ', str)
You can use find function.
str = '< a href="https://www.blabla/k20832 > word1 word2'
start_Index=str.find('<')
end_Index=str.find('>')
print(str[:start_Index+1]+str[end_Index:])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.