Reputation: 3
I'm trying to read a binary file.
My objective is to find all the matches of "10, 10, [any hex value exactly one time], either EE or DD]"
Thought I could do it like this:
pattern = (b"\x10\x10\[0-9a-fA-F]?\[xDD|xEE]")
Clearly not working. It seems that it becomes an error at the third part. I tried dissecting the statement and x10 and x11 works, but the rest just won't.
My understanding of "[0-9a-fA-F]?" is that it matches the range in the brackets 0 or 1 times. and the third part "xDD or xEE" am I wrong?
Any ideas?
Upvotes: 0
Views: 109
Reputation: 16224
Use the regex
b'\x10\x10.[\xdd\xee]'
A single .
matches any character (any one-byte) single time, and a single [ab]
matches a
or b
a single time.
>>> re.match(b'\x10\x10.[\xdd\xee]', b'\x10\x10\x00\xee')
<_sre.SRE_Match object; span=(0, 4), match=b'\x10\x10\x00\xee'>
Upvotes: 1