Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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
Python 从路径中提取html的正则表达式_Python_Regex - Fatal编程技术网

Python 从路径中提取html的正则表达式

Python 从路径中提取html的正则表达式,python,regex,Python,Regex,我对Regex不熟悉。 我需要从目录路径中提取2个内容。 ../path_to_html/myhtmlpage.html?附加_参数或_url 如何获取html的名称? 例如myhtmlpage 我如何获得整个url? 例如:myhtmlpage.html?video_url=www.google.com/video 多谢各位 给你: import re url = "/path_to_html/myhtmlpage.html?video_url=www.google.com/video" #

我对Regex不熟悉。 我需要从目录路径中提取2个内容。 ../path_to_html/myhtmlpage.html?附加_参数或_url

如何获取html的名称? 例如myhtmlpage

我如何获得整个url? 例如:myhtmlpage.html?video_url=www.google.com/video

多谢各位

给你:

import re
url = "/path_to_html/myhtmlpage.html?video_url=www.google.com/video"
# Name
print re.findall(r'/(\w+)\.html', url)[0]
# Entire url
print re.findall(r'/(\w+\.html.*)', url)[0]
这张照片是:

myhtmlpage
myhtmlpage.html?video_url=www.google.com/video

这些是本地计算机上的文件吗?或者你有一个你想要解析的url吗?你不能只搜索第一个出现的.html吗?通过这种方式,您可以知道url位于.html之前的最后一个“\”之间,并到达字符串的末尾。如果您对正则表达式不熟悉,您最好坐下来看一些文档,自己解决它。有人递给您一个您不懂的正则表达式,从长远来看不会为您提供很好的服务。我知道。稍后我将研究文档。我需要在紧急会议之前修改一些代码。我脑子里只有一件事,那就是堆积如山。谢谢你们,很好用!非常感谢。很高兴我能帮忙!完成。对不起,我是新来的:)