0
votes

Another question :

I'm trying to search for a specific pattern in a fiel , but I have to deal with the following case :

This line returns a correct interpretation

f27 = re.findall( b'\x03\x00\x00\x27''(.*?)''\xF7\x00\xF0', s)

but this one got badly interpreted as x28 is related to the '()' parenthesis

f28 = re.findall( b'\x03\x00\x00\x28''(.*?)''\xF7\x00\xF0', s)

Traceback (most recent call last): File "", line 1, in File "D:\Portable Python 2.7.2.1\App\lib\re.py", line 177, in findall return _compile(pattern, flags).findall(string) File "D:\Portable Python 2.7.2.1\App\lib\re.py", line 244, in _compile raise error, v # invalid expression error: unbalanced parenthesis

I tried with several escapes '\' and '/' but no way !

Any solution ?

Thx

1
What is s equal to? Cold you post an SSCCE? - MerreM
Yeah : s is a file put in a variable : f = open('d:\BB.ki', "rb") s = f.read() - Waraba

1 Answers

0
votes

Try using raw bytestrings. The re module itself understands escape sequences.

f28 = re.findall(br'\x03\x00\x00\x28(.*?)\xF7\x00\xF0', s)