php içinde kaçamayan karakterleri eşleştirmek

1 Cevap php

i PHP bir dize / sadece tek maç regexpi gerekir.

"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 /

bu yüzden sadece çıkmamış / istiyoruz.

1 Cevap

Bunun için zero-width assertions kullanabilirsiniz

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

Bu a / eşleşir, ama öncesinde değil ve başka bir takip değil sadece /

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