It is generally a good idea to provide a little code to demonstrate your issue and to show that you have put at least some effort in. It also helps if you show us what you expected to happen and what actually happens so we have a clear understanding of the problem and the required outcome. This is especially important when you are not a native English speaker or have difficulty describing the problem in prose.
It may be that what you are after is something like:
use strict;
use warnings;
my @strs = qw(id_1_1 id_2 banana id_1_2_);
for my $id (@strs) {
if ($id =~ /(\d)(?!_)/) {
print "Extracted $1 from $id\n";
} else {
print "no match for $id\n";
}
}
Prints:
Extracted 1 from id_1_1
Extracted 2 from id_2
no match for banana
no match for id_1_2_
DWIM is Perl's answer to Gödel
|