0

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

4

1 回答 1

0

尝试使用原始字节串。re 模块本身理解转义序列。

f28 = re.findall(br'\x03\x00\x00\x28(.*?)\xF7\x00\xF0', s)
于 2012-07-05T15:29:52.493 回答