james28909:

Changing the data to a character representation of the hex codes actually makes your task harder (as Athanasius indicated previously). If you have the data as a byte string, you can find the repeats like this:

while ($w =~ /((.)(\2{7}|\2{3}|\2))/sg) { ... do something ... }

Since you wanted only repeats of certain lengths, the regex is a little goofy. I had to put the sequences in descending order by length, otherwise it would just give the shortest version of the sequence.)

I played around with it a little and came up with an example:

#!/usr/bin/perl use strict; use warnings; my $t = pack "H*", '0a0a0a0a0b0b0a0a0c0c0c0c0c0c0c0c' . '1f1f2b2b2b2b3e3e7b7b7b7b7b7b7b7b' . '8f8f8f8f8f8f8f8f6c6c4b4b4b4b3f3f' . '9d9d0f0f0f0f0f0f0f0f3a3a2e2e2e2e'; repeats($t); repeats('abbcccddddeeeeeffffffggggggghhhhhhhhiiiiiiiii'); sub repeats { my $w = shift; print "\nBYTES: ", unpack("H*",$w),"\n"; while ($w =~ /((.)(\2{7}|\2{3}|\2))/sg) { my $bytes = $1; my $hex = unpack "H*", $bytes; $bytes =~ s/[\x00-\x1f\x80-\xff]/_/g; print "repeat: $hex ($bytes) pos:", pos($w)-length($bytes), "\ +n"; } }

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: matching characters and numbers with regex by roboticus
in thread matching characters and numbers with regex by james28909

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.