2016-07-14 78 views
0

我有perl腳本檢查SVN日誌並提取提交信息和驗證提交消息格式如下:Perl模式匹配問題而驗證

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 

所以我懷疑問題出在我的模式匹配。任何建議請。

回答

1

您的Program:\s{0,2}[A-Za-z]{3,20}圖案不允許空格,而您的輸入樣本Program: Some definite name有一些。在模式中添加空格應該可以解決問題:https://regex101.com/r/iA8kE9/1

+0

謝謝,解決了這個問題。 –