in reply to Help with regex, how to get the largest integer in a string?
Since There's always MTOWTDI (and I'm experimenting with look-ahead assertions):
#!/perl/bin/perl -w use strict; use Data::Dumper; use List::Util qw/ max /; my $s = "ASBSDEC 34 GADVVEEVEETTE 56 IOEOREAK GKJEOG EFEAF 1090 DAFFEE + 376"; # use a look-ahead assertion to split string into array of strings and + numbers # the corresponding string occupies the index immediately preceding th +e number my @arr = split /(\D+)(?=\d+)/, $s; # grep only for the numbers in the list, selecting the largest one print max(grep { /^\d+$/ } @arr), "\n"; __OUTPUT__ 1090
Update: Corrected typo diligently found by liverpole++
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Help with regex, how to get the largest integer in a string?
by MaxKlokan (Monk) on Apr 19, 2007 at 08:45 UTC | |
by naikonta (Curate) on Apr 19, 2007 at 14:31 UTC | |
by BrowserUk (Patriarch) on Apr 19, 2007 at 15:24 UTC | |
by naikonta (Curate) on Apr 19, 2007 at 15:52 UTC |