正则表达式:
(?xi)\A
# Skip over scheme and authority, if any
([a-z][a-z0-9+\-.]*:(//[^/?#]+)?)?
# Path
([a-z0-9\-._~%!$&'()*+,;=:@/]*)
Python代码:
import re
subject = 'http://www.regexcookbook.com/index.html'
reobj = re.compile(r'''(?xi)\A
# Skip over scheme and authority, if any
([a-z][a-z0-9+\-.]*:(//[^/?#]+)?)?
# Path
([a-z0-9\-._~%!$&'()*+,;=:@/]*)''')
match = reobj.search(subject)
if match:
print match.group(3)
Python 正则表达式提取URL中的Path
最新推荐文章于 2025-02-20 16:14:04 发布