Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Matching numeric value between two digits

by ww (Bishop)
on Feb 05, 2013 at 01:41 UTC ( #1017039=note: print w/ replies, xml ) Need Help??


in reply to Matching numeric value between two digits

The greedy death-star is another problem. You need to limit it:

C:\>perl -E "my $num ='abcd23.5fghi';if ($num =~ /[a-z]+(.*?)[a-z]/i){ + say $1;}" 23.5 /^\
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.5fgh # not what OP seems to want
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 ='abcd23fghi'; my $intermediate; if ($num =~ /[a- +d]+(\d+)[f-z]+/) {$intermediate = $1;} if ($intermediate =~ /[0-9]+/ +){ say $intermediate;}" 23
... whereas this fails:
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.


Comment on Re: Matching numeric value between two digits
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1017039]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2014-11-23 19:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (134 votes), past polls