How to use variable in the pattern ?
Please I want to this :
my $project="SDK" //or something that i will get it after calling some function.
my $JIRA_regex = '(^| )($project)-(\d+)';
print "pattern = $JIRA_regex\n";
Output is not good :
(^| )($project)-(\d+)
Thank you :)
1 - Yes I want to use $project, as string value to match or a regex too:
2 - $JIRA_regex will be matched further on the code.
This is my code that it works fine now :
my $repo=$ARGV[0];
my $comment=$ARGV[1];
my $project_pattern="[A-Z]{2,5}";
if ($repo =~ "test1.git" or $repo =~ "test2.git")
{
$project_pattern = "\QSDK\E";
}
my $JIRA_regex = "(^| )($project_pattern)-(\\d+)";
if ( $comment =~ /$JIRA_regex/m )
{
print "matched $2-$3\n";
}
else
{
print "not matched\n";
}