gpt4 book ai didi

php - 如何在 Amazon s3 SDK for PHP 中使用 get_object_list 方法编写 PCRE 正则表达式模式

转载 作者:搜寻专家 更新时间:2023-10-31 21:15:32 28 4
gpt4 key购买 nike

我正在使用 Amazon S3 SDK for PHP并尝试编写一个正则表达式来搜索动态路径中的子目录。我知道 Amazon S3 没有像典型文件系统那样的“子目录”,但根据我的理解,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]: Delimiter must not be alphanumeric or backslash in sdk-1.5.2/utilities/array.class.php on line 114

在 pcre 中编写此正则表达式的正确方法是什么?

最佳答案

您在 some/path" 中缺少左双引号。

您还应该使用在结果中找不到的分隔符。将 / 更改为 # 或其他内容。希望对您有所帮助,我没有任何其他想法。

关于php - 如何在 Amazon s3 SDK for PHP 中使用 get_object_list 方法编写 PCRE 正则表达式模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9653869/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com