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]
#1
0
Try this:
a=[e.replace("\\r\\n",'').split("<")[0] for e in a]