python - 烂番茄URL上的正则表达式——排除词干

标签 python regex rotten-tomatoes

我想返回电视剧网址的匹配项:

YES: http://www.rottentomatoes.com/tv/falling-skies/

但不在电视剧集或电视剧季中

NO: http://www.rottentomatoes.com/tv/falling-skies/s03
NO: http://www.rottentomatoes.com/tv/falling-skies/s12/e01

我目前有以下正则表达式:

match = re.match('(http(s)?://)?(www.)?rottentomatoes.com/tv/.+', url)

这与上述所有三个匹配。我将如何构造正则表达式以仅匹配第一个?

最佳答案

使用否定字符类代替 .+:

^http://www\.rottentomatoes\.com/tv/[^/]+/?$

[^/]+ 匹配任何不是斜杠的字符一次或多次 - 这是从 tv/ 到下一个斜杠(或结尾)的所有内容如果 / 不存在,则为字符串)。

RegEx Demo

关于python - 烂番茄URL上的正则表达式——排除词干,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25392099/

相关文章:

javascript - 使用 angularJS 和烂番茄进行 API 调用

python - 尝试使用 urllib3 和 json 获取烂番茄数据时出错(Python)

python - 通过多列组合查找 pandas 中的唯一记录

c++ - 无法编译(未声明且预期的主表达式)

c# - 正则表达式特定日期格式

android - 如何从 Rotten Tomatoes 的 API 访问特定的 JSON 数据

python - 如何找到 pandas 的总体平均值

python - 像素坐标和颜色未显示

Python:比较不同 bin 大小的直方图

javascript - 正则表达式选择除