如何将两个网址合并为Regex模式

时间:2018-10-01 02:51:54

标签: python regex pattern-matching

我用过 pattern = re.compile(r'(\/\/smtgvs\.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+\.[jpng]*)')

这似乎不正确...

1 个答案:

答案 0 :(得分:1)

以下模式应该起作用:

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

示例

https://regex101.com/r/i8a1tQ/2