从Python中的列表元素中删除URL
16lz
2021-01-22
I've used regular expressions module to get a sentence out of a string by using an adapted method from this post: Extract words surrounding a search word
我使用正则表达式模块通过使用此帖子中的改编方法从字符串中获取句子:提取搜索词周围的单词
re.search(r'((keyword)\W+((?:\w+\W+){,22}', sentence)
My resulting list looks like so:
我的结果列表如下所示:
['AL', 'KHOR\\r\\n<https://www.fleetmon.com/vessels/al-khor-f_0_11569260>', 'departed\\r\\nat']
How can I remove the url from the list element and the \r\n from the middle of the elements? Is there a way to exclude it in the re.search that would be better than trying to remove it after I've searched?
如何从列表元素中删除url,从元素中间删除\ r \ n?有没有办法在re.search中排除它比在我搜索后尝试删除它更好?
EDIT: URL will vary as it relates to individual ships. The address is the same up to /vessels
编辑:URL将因各个船舶而异。地址与/船只相同
1 个解决方案
#1
0
Try this:
a=[e.replace("\\r\\n",'').split("<")[0] for e in a]
更多相关文章
- 将字节列表转换为字节字符串
- python selenium-webdriver 定位frame中的元素 (十三)
- Django模型选择:使用元组的第一个元素
- Python列表以及列表的处理方法
- python入门之常见列表、字典知识
- python 按位置关系输出矩阵元素
- 如何使用不同的类python在一个类中的一个窗口中更新列表框
- python打印列表的下标和值的例子:
- 使用python如何在列表列表中找到元素,而关键元素是内部列表的元素