-1

我在 kaltura 中有一个文件名约定 {referenceId}_{flavor name}.mp4。或者,如果您熟悉 kaltura,请告诉我可以用于此命名约定的 slugRegex,它支持预编码文件摄取

我必须从中提取 referenceId 和文件名。

我在用着

/(?P)_(?P)[.]\w{3,}/
4

3 回答 3

4
var filename = "referenceId_flavor-name.mp4";
var parts = filename.match(/([^_]+)_([^.]+)\.(\w{3})/i);
// parts is an array with 4 elements
// ["referenceId_flavor-name.mp4", "referenceId", "flavor-name", "mp4];
于 2012-08-01T13:53:33.337 回答
0
var file = 'refID_name.mp4',
    parts = file.match(/^([^_]+)_(.+)\.mp4/, file);

返回数组:

[
    'refID_name.mp4', //the whole match is always match 0
    'refID', //sub-match 1
    'name' //sub-match 2
]
于 2012-08-01T13:58:45.877 回答
0
/**
 * Parse file name according to defined slugRegex and set the extracted parsedSlug and parsedFlavor.
 * The following expressions are currently recognized and used:
 *  - (?P<referenceId>\w+) - will be used as the drop folder file's parsed slug.
 *  - (?P<flavorName>\w+)  - will be used as the drop folder file's parsed flavor. 
 *  - (?P<userId>\[\w\@\.]+) - will be used as the drop folder file entry's parsed user id.
 * @return bool true if file name matches the slugRegex or false otherwise
 */
private function parseRegex(DropFolderContentFileHandlerConfig $fileHandlerConfig, $fileName, &$parsedSlug, &$parsedFlavor, &$parsedUserId)
{
    $matches = null;
    $slugRegex = $fileHandlerConfig->getSlugRegex();
    if(is_null($slugRegex) || empty($slugRegex))
    {
        $slugRegex = self::DEFAULT_SLUG_REGEX;
    }
    $matchFound = preg_match($slugRegex, $fileName, $matches);
    KalturaLog::debug('slug regex: ' . $slugRegex . ' file name:' . $fileName);
    if ($matchFound) 
    {
        $parsedSlug   = isset($matches[self::REFERENCE_ID_WILDCARD]) ? $matches[self::REFERENCE_ID_WILDCARD] : null;
        $parsedFlavor = isset($matches[self::FLAVOR_NAME_WILDCARD])  ? $matches[self::FLAVOR_NAME_WILDCARD]  : null;
        $parsedUserId = isset($matches[self::USER_ID_WILDCARD])  ? $matches[self::USER_ID_WILDCARD]  : null;
        KalturaLog::debug('Parsed slug ['.$parsedSlug.'], Parsed flavor ['.$parsedFlavor.'], parsed user id ['. $parsedUserId .']');
    }
    if(!$parsedSlug)
        $matchFound = false;
    return $matchFound;
} 

是处理正则表达式的代码。我使用/(?P<referenceId>.+)_(?P<flavorName>.+)[.]\w{3,}/并遵循本教程在此处输入链接描述

于 2015-08-19T14:34:51.443 回答