仅使用变量的一部分进行正则表达式搜索

时间:2016-07-19 00:34:39

标签: regex perl variables

    my $BestMatch = "CGGAGCTTTACGAGCCGTAGCCCAAACA";
    if ($Sequence -~ m/$BestMatch/){   

有没有办法修改正则表达式只搜索$ BestMatch序列中的前6个字母?我需要在正则表达式中保留$ BestMatch变量,我只需要修改它 我在网上找到的例子没有使用变量,而是整个序列本身。我的问题是$ BestMatch将针对foreach循环中打开的每个文件进行更改,因此无法进行硬编码。 谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

尝试类似:

my$substr = substr($BestMatch,0,6);

if ($Sequence -~ m/\Q$substr/){ 

    # ... whatevs ....

}

当然,如果它只是一个简单的字符串匹配,你甚至不需要使用正则表达式;只需使用the index() function