在php中匹配未转义的字符

mck*_*k89 1 php regex

我需要一个正则表达式来匹配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 /
Run Code Online (Sandbox Code Playgroud)

所以我只希望没有转义/.

Pau*_*xon 5

您可以为此使用零宽度断言

{(?<!/)/(?!/)}
Run Code Online (Sandbox Code Playgroud)

这匹配一个/,但前提是不在前面,而不是后面跟着另一个/

$escaped=preg_replace('{(?<!/)/(?!/)}', '//', $original); 
Run Code Online (Sandbox Code Playgroud)