如何正确编写正则表达式?

时间:2012-07-27 07:55:22

标签: php regex

$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的快捷方式)?

1 个答案:

答案 0 :(得分:0)

根据评论更新:

php > var_dump(preg_replace('/(?<=[^\\\\])\./', DIRECTORY_SEPARATOR, 'vendor.dummy\.test'));
string(18) "vendor/dummy\.test"