Here is my take (my takes actually):

#!/bin/perl -w use strict; my $numbers="1 1.0 3.547 92.34 12 .25 23.00 23.01 343.2234"; # I guess that's what you were looking for while($numbers=~/(?<![\.\d]) # first no digits or . (\d+) # digits (?!\d*\.\d) # then no digits, . and digits /gx) { print "$1 is an integer\n"; } print '-' x 20, "\n"; # the same thing slightly simpler while($numbers=~/(?:\A|[^\d\.]) # catches the character before a numb +er or the start of the string (\d+) # digits (?!\d*\.\d) # then no digits, . and digits /gx) { print "$1 is an integer\n"; } # much simpler I think while($numbers=~/([\d\.]+)/g) # catch all numbers { if( $1=~ /^(\d+)$/) # keep only integer ones { print "$1 is an integer\n"; } # this $1 from the if regexp } print '-' x 20, "\n"; # now maybe 1.0 is considered an integer while($numbers=~/(\d+(?:\.(\d+))?)/g) { my $nb= $1; # get all + numbers print "$nb is an integer\n" if( !$2 || ($2=~ /^0+$/) ); # keep th +ose with no decimal parts # or with + a deciaml part only made of 0's }

gives:

1 is an integer 12 is an integer -------------------- 1 is an integer 12 is an integer -------------------- 1 is an integer 12 is an integer -------------------- 1 is an integer 1.0 is an integer 12 is an integer 25 is an integer 23.00 is an integer

In reply to Re: How can I match all the integers in a string? by mirod
in thread How can I match all the integers in a string? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.