网址第一部分的子串正则表达式 [英] substring regex for first part of url
本文介绍了网址第一部分的子串正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个大型的项目和问题跟踪器数据库,其中一些具有url。
I've got a large database of projects and issue trackers, some of which have urls.
我想查询一下以找出列表的列表每个项目的url,但是很多我都想避免使用。
I'd like to query it to figure out a list of urls for each project, but many have extra data I'd like to avoid.
我想做这样的事情:
substring(tracker_extra_field_data.field_data FROM 'http://([^/]*).*')
除了一些URL是https,我想捕获它以及第一个子目录。
Except some urls are https, and I'd like to capture that as well as the first sub directory.
例如,给定URL:
https://dev.foo.com/bar/action/?param=val
我想选择返回:
https://dev.foo.com/bar/
在pgsql中使用子字符串/正则表达式有半简单的方法吗?
Is there a semi-simple way to do this with substring/regex in pgsql?
推荐答案
尝试一下:
选择子字符串('https://dev.foo.com/bar/action/?param=val'从'(https? ://([^ /] * /){1,2})' );
template1=# select substring('https://dev.foo.com/bar/action/?param=val' from '(https?://([^/]*/){1,2})');
substring
-------------------------
https://dev.foo.com/bar/
(1 row)
template1=# select substring('http://dev.foo.com/bar/action/?param=val' from '(https?://([^/]*/){1,2})');
substring
------------------------
http://dev.foo.com/bar/
这篇关于网址第一部分的子串正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文