我正试图通过正则表达式查询-/:\/\/s3\.amazonaws.com\/([^\/]+)|:\/\/([^.]+)\.s3\.amazonaws\.com\//
获取链接为“ https://darwin-ui-test.s3.amazonaws.com/bundles/bundleAlert”的存储桶名称(darwin-ui-test),但出现错误:{{1 }}
Possible Unhandled Promise Rejection
我希望得到带有键的对象:
const REGEX_BUCKET_NAME =
'/:\/\/s3\.amazonaws.com\/([^\/]+)|:\/\/([^.]+)\.s3\.amazonaws\.com\//';
const REGEX_BUNDLE_ROUTE = /bundles\/\w+/;
getBundleAndBucketNames = (link) => {
const matchesBucket = link.match(REGEX_BUCKET_NAME); // i'm assure, an error occupies here, but i don't know why
const matchesRoute = link.match(REGEX_BUNDLE_ROUTE);
return {
bundleRoute : matchesRoute[0],
bucketName : matchesBucket[2]
? matchesBucket[2]
: matchesBucket[1]
};
}
getBundleAndBucketNames('https://darwin-ui-test.s3.amazonaws.com/bundles/bundleAlert');
但是我得到了错误:{
bundleRoute : 'bundles/bundleAlert',
bucketName : 'darwin-ui-test'
}