2017-03-07 57 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