in reply to Matching numeric value between two digits
The above is OK (Yes, I know OP wants only INTs, but this is a minimal example of the death-star problem) when the greedy ".*" is limited by the "?" but it's definitely not what the OP seems to want if the limit ("?") is omitted.C:\>perl -E "my $num ='abcd23.5fghi';if ($num =~ /[a-z]+(.*?)[a-z]/i){ + say $1;}" 23.5 /^\
Also rather than the clumsy "/\d{1}-\d{2}/" you might wish to use "/[0-9]+/" and, more verbosely this also works (but is a far less stringent regex):C:\>perl -E "my $num ='abcd23.5fghi';if ($num =~ /[a-z]+(.*)[a-z]/i){ +say $1;}" 23.5fgh # not what OP seems to want
... whereas this fails:C:\>perl -E "my $num ='abcd23fghi'; my $intermediate; if ($num =~ /[a- +d]+(\d+)[f-z]+/) {$intermediate = $1;} if ($intermediate =~ /[0-9]+/ +){ say $intermediate;}" 23
C:\>perl -E "my $num ='abcd23.777fghi'; my $intermediate; if ($num =~ +/[a-d]+(\d+)[f-z]+/) {$intermediate = $1;} if ($intermediate =~ /[0-9 +]+/ ){ say $intermediate;}" (no output)
The previous discussion should make it easy to identify the cause of the failure.
|
|---|