Investigate double-slash logic
TAbdiukov opened this issue · comments
Recall
old = "(\\xD8\\x64\\x24\\x04\\xD9\\x99\\x3C\\x01\\x00\\x00)(.{0,8}?)(\\xC7\\x81\\x3C\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\xD9\\x81\\x3C\\x01\\x00\\x00)"
new = "\xD8\x64\x24\x04\x90\x90\x90\x90\x90\x90\g<2>\g<3>"
2 questions
- Why does "old" require double-slashes to work properly?
- why the script crashes if "new" has double-slash
re.compile
takes a string with double backslashes because it needs to know the exact characters to match in the regular expression. But re.subn
takes a string with single backslashes because it needs to know the actual characters to use in the replacement, not their escaped versions.
-
re.compile:
\\xAB
->r"\xAB"
-
re.subn:
\xAB
-> (byte)