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++
In reply to Re: Help with regex, how to get the largest integer in a string?
by thezip
in thread Help with regex, how to get the largest integer in a string?
by coltman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |