【问题标题】:Perl pattern matching issue while validating验证时出现 Perl 模式匹配问题
【发布时间】:2016-11-17 06:00:14
【问题描述】:

我有 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

 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

cmets 被提取并存储在一个数组中 - @my_cmets 并按如下方式访问

        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 

所以,我怀疑问题出在我的模式匹配上。请有任何建议。

【问题讨论】:

    标签: perl


    【解决方案1】:

    您的Program:\s{0,2}[A-Za-z]{3,20} 模式不允许空格,而您的输入样本Program: Some definite name 有一些空格。在模式中添加空格应该可以解决问题:https://regex101.com/r/iA8kE9/1

    【讨论】:

    • 谢谢,解决了这个问题。
    猜你喜欢
    • 1970-01-01
    • 2011-06-04
    • 2021-02-08
    • 2018-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-16
    • 1970-01-01
    相关资源
    最近更新 更多