我正在使用Amazon S3 SDK for PHP,并试图编写一个正则表达式来搜索动态路径中的子目录。我知道AmazonS3不像典型的文件系统那样有"子目录",但根据我的理解,get_object_list方法允许pcre选项在S3上的对象中查找字符串。通过使用pcre选项,我希望能够在路径中找到一个子目录。
例如。
$find_directory = "foo";
$reg_ex = "/([a-zA-Z0-9_]*)/";
$response = $s3->get_object_list(MY_BUCKET, array(
'pcre' => some/path/" . $reg_ex . "/" . $find_directory . "/",
'max-keys' => 1
));
if ( (count($response)) > 0){echo "yes it exists";}else{echo "no it does not exist";}
我希望它能找到任何具有以下内容的目录路径:
some/path/(any directory with letters, numbers, or underscores)/foo
但是这个正则表达式不起作用,或者我格式化pcre的方式不正确。
我收到警告:
preg_match()[function.preg match]:分隔符不能是字母数字或sdk-1.5.2/utilities/array.class.php中第114行上的反斜杠
在pcre中编写这个正则表达式的正确方法是什么?
some/path"
中缺少开头的双引号。
您还应该使用在结果中找不到的分隔符。将/
更改为#
或其他什么。希望有帮助,我没有其他想法。