I have a variable like this below:
G12345(@@)
How can I keep in the variable only the numbers 12345. I have done it before in PHP but I cannot find a way in Perl.
$v =~ s/\D//g; should do the trick.
(Regular expression substitute "Not a number" with "nothing", globally)
This can also be done without regular expressions: Transliterate: tr///
use warnings;
use strict;
my $s = 'G12345(@@)';
$s =~ tr/0-9//cd;
print "$s\n";
__END__
12345
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With