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. 将字节列表转换为字节字符串
  2. python selenium-webdriver 定位frame中的元素 (十三)
  3. Django模型选择:使用元组的第一个元素
  4. Python列表以及列表的处理方法
  5. python入门之常见列表、字典知识
  6. python 按位置关系输出矩阵元素
  7. 如何使用不同的类python在一个类中的一个窗口中更新列表框
  8. python打印列表的下标和值的例子:
  9. 使用python如何在列表列表中找到元素,而关键元素是内部列表的元素

随机推荐

  1. android 开发上传图片遇到返回 FileNotFo
  2. 11.时钟&计时器
  3. Android ListView(Selector 背景图片 全选
  4. Android碎片积累
  5. Android核心基础(五)
  6. 第12天android:短信发送+测试使用
  7. Android中NDK各版本下载
  8. Android(安卓)横竖屏幕切换
  9. Mac下获取android studio keystore的SHA1
  10. Android网络之HttpUrlConnection和Socket