$data = array(
'core.*',
'handlers.player.profile',
'vendor.dummy\.test'
);
$re = '/(?!<\\\\)\./';
foreach ($data as $path) {
$path = __DIR__ . DS . preg_replace($re, DS, $path) . '.php';
echo "$path <BR>";
}
如何定义正则表达式以执行\.
序列不转换为目录分隔符(DS是我项目中DIRECTORY_SEPARATOR的快捷方式)?
答案 0 :(得分:0)
根据评论更新:
php > var_dump(preg_replace('/(?<=[^\\\\])\./', DIRECTORY_SEPARATOR, 'vendor.dummy\.test'));
string(18) "vendor/dummy\.test"