Reputation: 64064
Given this two text:
$mir1 = 'microRNA-9a';
$mir2 = 'microRNA10a';
$mir3 = 'microrna3a';
I want to change it to:
miR-9a
miR-10a
miR-3a
In principle I'd like to replace all the variation microRNA
part with miR-
Is there any single regex to do that?
I tried this but not sure how to capture the digit part.
my $mirnew = $mir =~ s/microRNA(\d+)/miR-/gi;
Upvotes: 2
Views: 77
Reputation: 213371
You need to capture words, not digits after hyphen. To backreferecence to capture group, you use $1
:
s/microRNA-?(\w+)/miR-$1/gi;
Upvotes: 3
Reputation: 7912
You don't actually need to capture anything, just case insensitively replace microRNA
and an optional -
with miR-
:
s/microRNA-?/miR-/i;
Upvotes: 6