2015-11-05 31 views

回答

2

試試這個:

\/this\/that\/(?!99-text) 

https://regex101.com/r/yK4zH1/1

它採用了負先行,以確保它不跟99-text

如果你想/this/that可選斜線,你可以這樣做:

\/this\/that\/?(?!\/?99-text) 

https://regex101.com/r/pN3cJ6/1

把它一個額外的步驟,如果它是有效的有類似/this/that99-text,您可以執行以下操作:

\/this\/that(?:\/(?!99-text)|(?!\/99-text)) 

https://regex101.com/r/yV8cO8/1

+0

非常感謝,這似乎是一個簡單的問題,但我掙扎很多。第二個建議工作正常! –

0

使用負前瞻:

$URI="/this/that/99-text"; 

if(preg_match_all("#/this/that(?!/99-text)#", $URI,$matches)) 
{ 
    var_dump($matches); 
} 
else 
{ 
echo 'No matches found.'; 
} 
+0

謝謝,我試過(?!99 \ -text)/ this /,但它不起作用(它包含了包含/ this/that /的所有東西) –

相關問題