If it works with all the formats your data includes, that's what's important. As jwkrahn pointed out, by removing your leading .*, I did change the effect of yours in any case where there is more than one matching number in a string:
$str = 'This sentence has two numbers, +13 and -15.';
$str =~ /([+-]?\d+)/; # matches +13, first match found
$str =~ /.*([+-]?\d+)/; # matches -15 because .* is greedy
So which of those you use depends on whether you want to find the first number or the last number in a line. If your lines only have one number, it won't matter.
|