我想匹配在以下链接类别:news
和politics
使用python正则表达式匹配URL中的类别?
注意,可能有1个或多个类别。可以通过在文本或/
之间使用/
来识别类别。
我的尝试:
item.url = 'http://www.example.com/news/politics/this-is-article-name-1993591'
compiled_regex = re.compile('/.+(?!/)/')
match = compiled_regex.search(item.url)
响应None
我想什么(预期结果):
match.group(0) = `news`
match.group(1) = `politics`
什么是预期的输出 ?有没有你想要的图案?请稍微清楚一点。 – 2016-03-04 13:47:54