in reply to Repeated Pattern Matching Fails
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Repeated Pattern Matching Fails
by kapila (Acolyte) on Apr 14, 2009 at 11:40 UTC | |
by shmem (Chancellor) on Apr 14, 2009 at 12:11 UTC | |
by kapila (Acolyte) on Apr 15, 2009 at 08:51 UTC | |
by parv (Parson) on Apr 15, 2009 at 10:10 UTC |