In perl, if I have a string $str and a pattern saved in $pat and I want to replace what is saved in $pat with 'nothing' only if $pat appears at the end of $str, how would the regular expression look like? I tried different versions of this - s/\$pat$//
That, and all variations( s/$pat$//, s/\${pat}$//, s/${pat}$//) are not working :|
my $str = " aaa.::aa*bb/bb*cc:1/cc\n xxx.::xx*yy/yy*zz:1/xx\n"; my $pat = "xxx.::xx*yy/yy*zz:1/xx"; $str =~ s/$pat\n$//; print $str;