2017-03-07 60 views
0

我想的第一行,而不是别人匹配:匹配负先行PostgreSQL的红移POSIX正则表达式

http://example.com/shop/some-section/thing 
http://example.com/shop/b/thing 
http://example.com/shop/product/thing 

我想这样的正则表达式没有运气:

/shop/[^(b/)(product/)].*$ 

我m寻找一种解决方案,专门匹配没有/ b /或/ product /的字符串的URL部分。在我的正则表达式结尾的.*部分只是一个占位符,我将在实际代码中与其他字符匹配。

+0

有无通过合并两个正则表达式查询发现的另一种方法:'选择(URL〜 '/shop/.*$')和(网址! 〜'/ shop /(b | product)/')作为来自my.table的网址 – AlexG

+0

模式看起来不错。这是什么意思*没有运气*? – klin

+0

@klin我的意思是它不起作用。 [这里是一些相关的文档](http://docs.aws.amazon.com/redshift/latest/dg/pattern-matching-conditions-posix.html)那些不熟悉红移的人 – AlexG

回答

1

如果你的情况是不够具体,你可以使用SPLIT_PART

select split_part('http://example.com/shop/some-section/thing', '/', 5) not in ('b', 'product'); 
    ?column? 
    ---------- 
    t 

select split_part('http://example.com/shop/b/thing', '/', 5) not in ('b', 'product'); 
    ?column? 
    ---------- 
    f 

select split_part('http://example.com/shop/product/thing', '/', 5) not in ('b', 'product'); 
    ?column? 
    ---------- 
    f