Ah! I missed what you were driving at, having mis-read your input as '33332' not 33,332 '3's :-(

You are quite correct, 1 while ... will make a mull of it in that case. You could keep the 1 while ... by adding the \G anchor at the beginning of the pattern but there's not really much point in doing that.

use strict; use warnings; my $t1; my $t2; $t1 = $t2 = q{3} x 33335 . q{7}; print qq{Sequences of 3s:-\n}; print qq{>@{ [ length $1 ] }<\n} while $t1 =~ m{(3+)}g; print q{-} x 50, qq{\n}; 1 while $t1 =~ s{\G((?:3{4})+)}{ qq{[@{ [ length $1 ] }]} }eg; print qq{With 1 while and \\G\n$t1\n@{ [ q{-} x 50 ] }\n}; $t2 =~ s{((?:3{4})+)}{ qq{[@{ [ length $1 ] }]} }eg; print qq{Without either\n$t2\n@{ [ q{=} x 50 ] }\n};

Produces

Sequences of 3s:- >33335< -------------------------------------------------- With 1 while and \G [33332]3337 -------------------------------------------------- Without either [33332]3337 ==================================================

I'm not sure what you mean regarding saving typing as I am using Multiplicative Operators (your link is slightly broken, BTW).

Cheers,

JohnGG

Update: Further testing shows that the \G solution doesn't work with more than one group of 4 or more 3s.


In reply to Re^4: Regex exact pattern match problem! by johngg
in thread Regex exact pattern match problem! by Jts

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.