s/((\D)\2+)/length($1).$2/ge;
it search for a non-number, then search if it's repeated 1 or more times, then replace it by the count of them followed by the the repeated char
Oha

PS: could be usefull to limit the number of repeated matches, and include the numbers. but in this case numbers must always have a counter:

s/((\D)\2{1,8}|(\d)\3{0,8})/length($1).$2.$3/ge;
this one will compare 2 or more char, or 1 or more if digit and match no more then a sequence of 9.
in this way you can decode the data with no side-effect if strange data is used: X2AAAAAAAAAAAAAAAAAAAAAAA1111 become X129A9A5A41
A repetitions are grouped up to a max of 9, numbers are counted as repetition also if not repeated.
to decode use:
s/(\d)(.)/$2x$1/ge;

Oha


In reply to Re: Compressing a text file using count of continous characters by oha
in thread Compressing a text file using count of continous characters by nirvana4ol

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.