[ATCG]+ # one or more of any of A,T,C,G
# followed by
([ATCG]) # exactly one of A,T,C,G
# which is captured into $1
# followed by
\.+ # one or more dots
# followed by
$ # the end of the string
####
perl -Mstrict -wE '
my $str = "ATCGATCG...";
if($str=~/[ATCG]+([ATCG])\.+$/) {
my $last_char=$1;
say $last_char;
my $pos = rindex($str, $last_char);
say $pos;
}
'
G
7
####
perl -Mstrict -wE '
my $str = "ATCGATCGA...";
if($str=~/[ATCG]+([ATCG])\.+$/) {
my $last_char=$1;
say $last_char;
my $pos = rindex($str, $last_char);
say $pos;
}
'
A
8