Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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 如何以正则表达式模式组合两个URL_Python_Regex_Pattern Matching - Fatal编程技术网

Python 如何以正则表达式模式组合两个URL

Python 如何以正则表达式模式组合两个URL,python,regex,pattern-matching,Python,Regex,Pattern Matching,我曾经 pattern=re.compile(r'(\/\/smtgvs\.weathernews\.jp\/s\/topics\/img\/\d+\/\w+\.[jpng]*)要查找所有URL,现在我发现有一些URL\/\/smtgvs\.cdn\.weathernews\.jp\/s\/topics\/img\/\d+/\w+\.[jpng]*) 如何结合这两种模式?我尝试了pattern=re.compile(r'(\/\/smtgvs\[.cdn]*\.weathernews\.jp\/

我曾经
pattern=re.compile(r'(\/\/smtgvs\.weathernews\.jp\/s\/topics\/img\/\d+\/\w+\.[jpng]*)
要查找所有URL,现在我发现有一些URL
\/\/smtgvs\.cdn\.weathernews\.jp\/s\/topics\/img\/\d+/\w+\.[jpng]*)

如何结合这两种模式?我尝试了
pattern=re.compile(r'(\/\/smtgvs\[.cdn]*\.weathernews\.jp\/s\/topics\/img\/\d+\/\w+\.[jpng]*)


这似乎不正确…

以下模式应该有效:

\/\/smtgvs\.(?:cdn)*\.*weathernews\.jp\/s\/topics\/img\/\d+\/\w+\.[jpng]*
示例


您可以使用:
pattern=re.compile(r'//smtgvs(?:\.cdn)?\.weathernews\.jp/s/topics/img/\d+/\w+\(?:png | jpe?g)