i think this will work for you:
/\x26\x67(?!\x26\x67)(.(?!\x26\x67)){6}.{2}/s
Based upon this test code to try to match ab followed by 4 bytes w/no ab sequence:
perl -le 'print for map { /ab(?!ab)(.(?!ab)){2}.{2}/s ? $& : () } @AR
+GV' abhjabdf abasdasd abdasdadsab ababblah
OUTPUTS:
abasda
abdasd
abblah
Update: Here's a commented version:
/
\x26\x67 # Starting sequence (let's call it AB)
(?!\x26\x67) # Exclude double starting seqeuence, e.g. ABAB
(?: # non-capture
.(?!\x26\x67) # Any character that's not followed by the sequenc
+e
){6} # Need N-2 of these
.{2} # And the last two characters can be anything.
# note we know they're not AB because otherwise the
# (N-2)th item in the previous part wouldn't have mat
+ched
/sx # Enable comments, and make . mean everything
Update: Here's a generic version:
my $marker = '&g';
my $N = 8;
my $n1 = $N-2;
/$marker(?!$marker)(?:.(?!$marker)){$n1}.{2}/s
Update: (As pointed out by
diotalevi) Added the
/s modifier in case the data stream can have a newline in it.
-
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.