我有perl脚本,它检查SVN日志并提取提交消息并验证提交消息格式如下:
TAL: 12345, JIRA: QC-11115, BBC: ACR-12334
Program: Some definite name
Reviewer: committer name or his employee ID (5digits)
Description: Some relevant description
OR
JIRA: ABC-123
Program: Some definite name
Reviewer: committer name or his employee ID (5digits)
Description: Some relevant description:
- Some more relevant description
- Much relevant description
提取注释并将其存储在数组中 - @my_comments ,并按如下所示进行访问
if (($my_comments[$j] =~/(((JIRA|TAL|BBC):\s{0,2}[A-Za-z0-9-]{4,15},{0,1}\s{0,2}){1,5})\nProgram:\s{0,2}[A-Za-z]{3,20}\nReviewer:\s{0,2}[A-Za-z0-9\s]{4,40}\nDescription:\s{0,2}[A-Za-z0-9\s].*/))
{ print "GOOD";
$compliance = "YES";
}
else
{ print "FAILED";
$compliance = "NO";
}
push @my_Compliance,$compliance;
.....
此外,FYR
print "ARRAY COMMENTS:$my_comments[$j]\n";
按预期提供如下输出
TAL: 12345, JIRA: QC-11115, BBC: ACR-12334
Program: Some definite name
Reviewer: committer name or his employee ID (5digits)
Description: Some relevant description
所以,我怀疑问题与我的模式匹配有关。请提出任何建议。
答案 0 :(得分:1)
当您的输入样本Program:\s{0,2}[A-Za-z]{3,20}
包含空格时,您的Program: Some definite name
模式不允许使用空格。在模式中添加空格应该可以解决问题:https://regex101.com/r/iA8kE9/1。