1
我當前的URL:正則表達式匹配的URL
ristoranti/location/latvia/riga/other-tag
我需要一個正則表達式沒有得到URL如果有location
段
這裏是我的嘗試:
ristoranti/(?!location$).*)?(.+?)/(.+?)
示例url我需要得到:
ristoranti/latvia/riga/other-tag
我不太擅長正則表達式,但如果我是正確的第一部分除了location
,我錯了嗎?
的可能的複製(http://stackoverflow.com/questions/ [什麼是最好的正則表達式來檢查一個字符串是否是一個有效的URL?] 161738/what-is-best-regular-expression-to-check-if-a-string-is-a-valid-url) –
您需要使用簡單的字符串操作從字符串中移除'/ location /' 。或者使用兩個捕獲組,例如'(ristoranti /)[^/]*/(.+?)'並替換爲$ 1 $ 2'。 –
我無法用任何操作移除'/ location /' –