2009-08-28 67 views
1

我需要一個正則表達式來匹配PHP中只有一個字符串中的/。匹配非轉義字符在PHP

"bla bla bla/bla bla bla" //The regexp must match the/character 
"bla bla // bla bla/bla bla" //The regexp must match only the last/not the first beacuse it is followed by another/

所以我只想要非轉義/。

回答

5

您可以使用zero-width assertions

{(?<!/)/(?!/)} 

此相匹配的/,但前提是不被前面和後面沒有另一個/

$escaped=preg_replace('{(?<!/)/(?!/)}', '//', $original); 
+0

我不知道...謝謝 – mck89 2009-08-28 08:11:01