Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查找2个字符之间的字符串正则表达式python_Python_Regex_Python 2.7_Python 2.x - Fatal编程技术网

查找2个字符之间的字符串正则表达式python

查找2个字符之间的字符串正则表达式python,python,regex,python-2.7,python-2.x,Python,Regex,Python 2.7,Python 2.x,我正在尝试在html中查找URL。这就是我试图匹配的示例: href=“http://(.+)”(?:.+) 这符合: www.etf.rs/“目标= 它应该: www.etf.rs** 如果它匹配一些不规则的东西并不重要,但重要的是所有URL都匹配。谢谢!您可以使用re.search: import re s = '<a href="http://www.etf.rs/" target="_top">' print re.search('"http://(.*)"\s', s

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

href=“http://(.+)”(?:.+)


这符合: www.etf.rs/“目标=

它应该: www.etf.rs**


如果它匹配一些不规则的东西并不重要,但重要的是所有URL都匹配。谢谢!

您可以使用
re.search

import re

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

的副本?我不想让它包含http://and 有些链接以https://too
href=“https?:/([^“]+)”开头
是的,谢谢,这很有效!如果你不喜欢这个答案,请留下评论,否则就没用了欢迎你,我的评论是针对那些没有评论就投了反对票的人的,没有评论很难理解答案中的错误
import re

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