in reply to Regex to extract digits
I want to extract the two right most digits after the minus sign
A number of regexp examples have been given, but if you know your data, there are simpler ways. If you know the last two characters are the digits:
my $two = substr($val, -2);Or, if you know the last two characters are digits if the third-last character is a dash:
my $two = substr($val, -2) if substr($val, -3, 1) eq '-';
- another intruder with the mooring of the heat of the Perl
|
|---|