Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-18 07:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found