提取主机+路径中的一个文件夹
你能帮我找出一个正则表达式,
- 当其后面的路径中没有指定文件夹时,该正则表达式将从 url:
host name 中提取 例如
http://jj.com/'-> 'jj.com http://jj.com/index.php'-> 'jj.com http://jj.com/query?q=http://kk.uk' -> 'jj.com
主机名 + 路径中的一个文件夹(当路径中至少指定了一个文件夹时) 例如
'http://jj.com/site/index.php' -> 'jj.com/site' 'http://jj.com/site/second/aldldls.html' -> 'jj.com/site'
是否可以仅使用一个正则表达式来做到这一点?
顺便说一句,我将使用 hive 中的 regex_extract 函数,但任何可以做到这一点的正则表达式变体(例如 perl 正则表达式)都将非常有用。
Could you help me figure out a regular expression that would extract from url:
host name when there is no folder specified in the path that follows it
e.g.http://jj.com/' -> 'jj.com http://jj.com/index.php' -> 'jj.com http://jj.com/query?q=http://kk.uk' -> 'jj.com
host name + one folder from path when there is at least one folder specified in the path
e.g.'http://jj.com/site/index.php' -> 'jj.com/site' 'http://jj.com/site/second/aldldls.html' -> 'jj.com/site'
Is it possible to do that with just one regular expression?
BTW I will be using regex_extract function from hive but any variation of regex (e.g. perl regex) that can do that would be extremely useful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
输出
Output
输出:
Output: