in reply to regexp: extracting info
Well, your description of the extraction rules and what you expect to encounter are somewhat sparse, but if the number will always be at the end of the string, something simple might do the trick for you:
use strict; my $str = "abc dddd 10 "; my $number; if ($str =~ /^.*?(\d+)\s*$/) { $number = $1; } else { # do something with unexpected record }
Alternatively, you may be looking for two or three words, like this:
if ($str =~ /^(\w+\s+){2,3}(\d+)/) { $number = $2; }
(code not tested)
|
|---|