baba yaga baba yaga - 4 months ago 10
Perl Question

Perl pattern matching issue while validating

I have perl script which checks the SVN Log and extract the commit message and validate for the commit message format as below :

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


comments are extracted and stored in an array - @my_comments and accessed like below

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;
.....


Also , FYR

print "ARRAY COMMENTS:$my_comments[$j]\n";


gave output like below as expected

TAL: 12345, JIRA: QC-11115, BBC: ACR-12334
Program: Some definite name
Reviewer: committer name or his employee ID (5digits)
Description: Some relevant description


So , I suspect issue is with the my pattern matching. Any suggestions please.

Answer

Your Program:\s{0,2}[A-Za-z]{3,20} pattern does not allow spaces while your input sample Program: Some definite name has some. Adding spaces into the pattern should solve the issue: https://regex101.com/r/iA8kE9/1.