I am analyzing stream hex data using python regex. I have the following package structure that I am trying to extract from a packet stream:
'\xaa\x01\xFF\x44'
- \ xaa - start of package
- \ x01 - data length [value can vary from 00-FF]
- \ xFF - data
- \ x44 - end of package
I want to use the python regex to indicate how much of the package data should match as such:
r = re.compile('\xaa(?P<length>[\x00-\xFF]{1})(.*){?P<length>}\x44')
this compilation without errors, but it does not work. I suspect this does not work because the regex mechanism cannot convert a hexadecimal value named group <length>named to an appropriate integer for use inside the regex expression {}. Is there a way by which this can be done on python without resorting to the spread of matching groups?
Background: I used erlang to unpack packages, and I was looking for something like this in python
source
share