The immediate reason that this very complex regex stops where it does is that it doesn't take into account the possibility of "S.txt" in the middle of the line. Thus it stops matching when it bumps into that part of the line. Only matches in the part before "S.txt" are getting printed out. However, even without that annoying "S.txt", there are several other problems with your regex and I also wonder if we might have an XY Problem.

Judging by your response to targetsmart and the code you've shown above, you seem to just want to strip the introductory label and replace runs of spaces with "==". if that is the case then why not do something simple like this:

my $sNoLabel = substr($var, length("FILES CHECKED IN:")); $sNoLabel =~ s/\s+/==/g; print "MATCH$sNoLabel\n";

On the other hand, if you wanted to do something else, e.g. print out "TEST" and the version numbers but skip past that pesky "S.txt", then it might help to understand a bit better what the regex you currently have is doing. I have a feeling it is not what you think:

Putting this altogether here is how we would capture "TEST" and the revision numbers, but skip past "S.txt":

#move match start forward to after label # g tells Perl to save the point where we stopped matching $var =~ /^FILES CHECKED IN:\s+/g; #capture label and move match start to after TEST my ($sName) = ($var =~ /(\w+)/g); #capture the remaining revision numbers (ignore S.txt) my @aRevnums = ($var =~ /(\d+\.\d+(?:\.\d+)*)/g); print "$sName: @aRevnums\n";

Best, beth


In reply to Re: Repeated Pattern Matching Fails by ELISHEVA
in thread Repeated Pattern Matching Fails by kapila

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.