【问题标题】:Find string between 2 chars regex python在2个字符正则表达式python之间查找字符串
【发布时间】:2016-01-26 01:40:57
【问题描述】:

我正在尝试在 html 中查找 URL。这是我要匹配的示例:

href="http://(.+)"(?:.+)

<a href="http://www.etf.rs/" target="_top">

这匹配: www.etf.rs/" 目标=

它应该: www.etf.rs**

它是否匹配一些垃圾内容并不重要,但重要的是所有 URL 都匹配。谢谢!

【问题讨论】:

标签: python regex python-2.7 python-2.x


【解决方案1】:

你可以使用re.search:

import re

s = '<a href="http://www.etf.rs/" target="_top">'
print re.search('"http://(.*)"\s', s).group(1)

输出:

www.etf.rs/

【讨论】:

  • 如果你不喜欢答案,请发表评论,否则没用
  • 不客气,我的评论是针对没有评论而投反对票的人,如果没有评论,很难理解答案中的错误
猜你喜欢
  • 1970-01-01
  • 2019-05-19
  • 2012-05-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-27
  • 1970-01-01
  • 2014-10-01
相关资源
最近更新 更多