Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 下划线前后的正则表达式匹配模式_Java_Php_Javascript_Regex_Kaltura - Fatal编程技术网

Java 下划线前后的正则表达式匹配模式

Java 下划线前后的正则表达式匹配模式,java,php,javascript,regex,kaltura,Java,Php,Javascript,Regex,Kaltura,我在kaltura中有一个文件名约定{referenceId}{flavor name}.mp4。 或者,如果您熟悉kaltura,请告诉我我可以使用slugRegex进行命名约定,以支持预编码文件摄取 我必须从中提取引用ID和文件名 我正在使用 /(?P)_(?P)[.]\w{3,}/ 返回数组: [ 'refID_name.mp4', //the whole match is always match 0 'refID', //sub-match 1 'name'

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

我必须从中提取引用ID和文件名

我正在使用

/(?P)_(?P)[.]\w{3,}/
返回数组:

[
    'refID_name.mp4', //the whole match is always match 0
    'refID', //sub-match 1
    'name' //sub-match 2
]
/**
*根据定义的slugRegex解析文件名,并设置提取的parsedSlug和parsedFlavor。
*当前识别并使用以下表达式:
*-(?P\w+)-将用作放置文件夹文件的已解析段塞。
*-(?P\w+)-将用作放置文件夹文件的解析样式。
*-(?P\[\w\@.]+)-将用作放置文件夹文件项的已解析用户id。
*@return bool true(如果文件名与slugRegex匹配),否则返回false
*/
私有函数parseRegex(DropFolderContentFileHandlerConfig$fileHandlerConfig、$fileName、&$parsedSlug、&$parsedFlavor、&$parsedUserId)
{
$matches=null;
$slagregex=$fileHandlerConfig->getslagregex();
如果(为空($slugRegex)|为空($slugRegex))
{
$slagregex=self::DEFAULT\u SLUG\u REGEX;
}
$matchFound=preg_match($slugRegex,$fileName,$matches);
KalturaLog::debug('slug regex:'.$slugRegex.'文件名:'.$fileName);
如果($matchfind)
{
$parsedSlug=isset($matches[self::REFERENCE\u ID\u WILDCARD])?$matches[self::REFERENCE\u ID\u WILDCARD]:null;
$parsedFlavor=isset($matches[self::FLAVOR\u NAME\u WILDCARD])?$matches[self::FLAVOR\u NAME\u WILDCARD]:null;
$parsedUserId=isset($matches[self::USER\u ID\u WILDCARD])?$matches[self::USER\u ID\u WILDCARD]:null;
KalturaLog::debug('Parsed slug['.$parsedSlug.],Parsed flavor['.$parsedFlavor.],Parsed user id['.$parsedUserId.]');
}
如果(!$parsedSlug)
$matchFound=false;
返回$matchfind;
} 

是处理正则表达式的代码。我使用了
/(?P.+)(?P.+)[.]\w{3,}/
,在本教程之后

实际上我有一个文件名abc_1000.mp4,其中abc是参考Id,1000是味道名。我使用的是(?P)(?P)[.]\w{3,}/。referenceId是组名,所以flavorName是。我通过删除正则表达式解决了这个问题。kaltura将其视为默认值
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
]
/**
 * 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;
}