in reply to regex for negating a sequence
Based upon this test code to try to match ab followed by 4 bytes w/no ab sequence:/\x26\x67(?!\x26\x67)(.(?!\x26\x67)){6}.{2}/s
Update: Here's a commented version: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 generic 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: (As pointed out by diotalevi) Added the /s modifier in case the data stream can have a newline in it.my $marker = '&g'; my $N = 8; my $n1 = $N-2; /$marker(?!$marker)(?:.(?!$marker)){$n1}.{2}/s
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex for negating a sequence
by ikegami (Patriarch) on Oct 03, 2006 at 19:35 UTC | |
by ysth (Canon) on Oct 03, 2006 at 20:25 UTC | |
by davidrw (Prior) on Oct 03, 2006 at 20:40 UTC | |
|
Re^2: regex for negating a sequence
by diotalevi (Canon) on Oct 03, 2006 at 18:36 UTC |