Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
鉴于这两个文本:
$mir1 = 'microRNA-9a'; $mir2 = 'microRNA10a'; $mir3 = 'microrna3a';
我想将其更改为:
miR-9a miR-10a miR-3a
原则上,我想microRNA用是否有任何单一的正则表达式来替换所有变体部分miR- ?
microRNA
miR-
我试过了,但不确定如何捕捉数字部分。
my $mirnew = $mir =~ s/microRNA(\d+)/miR-/gi;
您实际上不需要捕获任何内容,只需不区分大小写替换microRNA和可选-with miR-:
-
s/microRNA-?/miR-/i;
您需要捕获单词,而不是连字符后的数字。要反向引用以捕获组,请使用$1:
$1
s/microRNA-?(\w+)/miR-$1/gi;
s/\bmicrorna.*?([\d]+a)\b/miR-$1/ig