I would like the regex to match a sequence of bytes when the string '02 d0 'does not occur at a specific position in the string. The position in which this line of two bytes cannot be executed is the positions of bytes 6 and 7, starting from the 0th byte on the right side.
This is what I used for testing:
#!/usr/bin/python import re p0 = re.compile('^24 [\da-f]{2} 03 (01|03) [\da-f]{2} [\da-f]{2} [\da-f]{2} (([^0])| (0[^2])|(02 [^d])|(02 d[^0])) 01 c2 [\da-f]{2} [\da-f]{2} [\da-f]{2} 23') p1 = re.compile('^24 [\da-f]{2} 03 (01|03) [\da-f]{2} [\da-f]{2} [\da-f]{2} (([^0])|(0[^2])|(02 [^d])|(02 d[^0])) 01') p2 = re.compile('^24 [\da-f]{2} 03 (01|03) [\da-f]{2} [\da-f]{2} [\da-f]{2} (([^0])|(0[^2])|(02 [^d])|(02 d[^0]))') p3 = re.compile('^24 [\da-f]{2} 03 (01|03) [\da-f]{2} [\da-f]{2} [\da-f]{2} (?!02 d0) 01') p4 = re.compile('^24 [\da-f]{2} 03 (01|03) [\da-f]{2} [\da-f]{2} [\da-f]{2} (?!02 d0)') yes = '24 0f 03 01 42 ff 00 04 a2 01 c2 00 c5 e5 23' no = '24 0f 03 01 42 ff 00 02 d0 01 c2 00 c5 e5 23' print p0.match(yes)
I looked through this example , but this method is less restrictive than I need. Can someone explain why I can only fit correctly when a negative look is ahead at the end of the line? What do I need to do to match when '02 d0 'does not occur in this particular bit position?
Michael
source share