Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I know this is outside the scope of the original question but this is a good opportunity to try your hand at some testing! Sometimes a regexp might look like it will do the job but how can you be SURE it does what you expect?

Try the following code:

use Test::Simple tests => 14; use strict; # # PUT THE REGEXP TO TEST HERE # my $testregexp = qr/\x26\x67(?!.{0,6}\x26\x67).{8}/s; sub mytest( $ ) { return( ( $_[0] =~ m/$testregexp/ ) ? 1 : 0 ); } # tests ok( mytest( "\x26\x67________" ), "lead bytes followed by 8 clear bytes" ); ok( !mytest( "\x26\x67_______" ), "lead bytes followed by only 7 clear bytes" ); ok( mytest( "\x26\x67_________" ), "lead bytes followed by 9 clear bytes" ); ok( !mytest( "\x26\x67\x26\x67______" ), "lead bytes with 2 bad bytes" ); ok( !mytest( "\x26\x67_\x26\x67_____" ), "lead bytes with 2 bad bytes" ); ok( !mytest( "\x26\x67_____\x26\x67_" ), "lead bytes with 2 bad bytes" ); ok( !mytest( "\x26\x67______\x26\x67" ), "lead bytes with 2 bad bytes" ); ok( mytest( "\x26\x67________\x26\x67" ), "lead bytes with 1 bad byte inside the eight byte limit" ); ok( mytest( "\x26\x67_______\x26\x67" ), "lead bytes with 1 bad bytes" ); ok( !mytest( "\x26\x67\x26\x67\x26\x67____" ), "lead bytes with 2 sets of bad bytes" ); ok( !mytest( "\x26\x67\x26\x67_\x26\x67___" ), "lead bytes with 2 sets of bad bytes" ); ok( !mytest( "\x26\x67_\x26\x67\x26\x67___" ), "lead bytes with 2 sets of bad bytes" ); ok( !mytest( "\x26\x67_\x26\x67___\x26\x67" ), "lead bytes with 2 sets of bad bytes" ); ok( !mytest( "\x26\x67\x26\x67____\x26\x67" ), "lead bytes with 2 sets of bad bytes" );

You can see that I've tried to cover all the cases I can think of in your requirements. Do they look right? Do the test situations describe all the match/nomatch situations you're expecting?

The test script produces the following output:

C:\temp>perl -w regexp.t 1..14 ok 1 - lead bytes followed by 8 clear bytes ok 2 - lead bytes followed by only 7 clear bytes ok 3 - lead bytes followed by 9 clear bytes ok 4 - lead bytes with 2 bad bytes ok 5 - lead bytes with 2 bad bytes ok 6 - lead bytes with 2 bad bytes ok 7 - lead bytes with 2 bad bytes ok 8 - lead bytes with 1 bad byte inside the eight byte limit ok 9 - lead bytes with 1 bad bytes ok 10 - lead bytes with 2 sets of bad bytes ok 11 - lead bytes with 2 sets of bad bytes ok 12 - lead bytes with 2 sets of bad bytes ok 13 - lead bytes with 2 sets of bad bytes ok 14 - lead bytes with 2 sets of bad bytes

You can plug in anybody's suggestion into the script and verify that it does, indeed, do what you want. If you get the hang of a little testing now you'll find it easier for other things too! Good luck!


In reply to Re: regex for negating a sequence by monarch
in thread regex for negating a sequence by spurperl

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (3)
    As of 2019-07-18 07:34 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?