Substituting part of words in Perl regex -
given 2 text:
$mir1 = 'microrna-9a'; $mir2 = 'microrna10a'; $mir3 = 'microrna3a';
i want change to:
mir-9a mir-10a mir-3a
in principle i'd replace variation microrna
part mir-
there single regex that?
i tried not sure how capture digit part.
my $mirnew = $mir =~ s/microrna(\d+)/mir-/gi;
you need capture words, not digits after hyphen. backreferecence capture group, use $1
:
s/microrna-?(\w+)/mir-$1/gi;
Comments
Post a Comment