-2
패턴에서 변수를 사용하는 방법은 무엇입니까?perl은 패턴 정규 표현식에서 변수를 사용합니다.
내가이 원하는하십시오 :
my $project="SDK" //or something that i will get it after calling some function.
my $JIRA_regex = '(^|)($project)-(\d+)';
print "pattern = $JIRA_regex\n";
출력은 좋지 않다 :
(^|)($project)-(\d+)
당신을 :) 감사
1 - 네,이 $ 프로젝트를 사용하려면, 일치하는 문자열 값 또는 정규 표현식 :
2 - $ JIRA_regex가 코드에서 더 일치합니다.
이
은 잘 지금 작동하는 내 코드입니다 :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";
}