I'm trying to perform a regex substitution on a bytes variable but I receive the error
sequence item 0: expected a bytes-like object, str found
Here is a small code example to reproduce the problem with python3:
import re
try:
test = b'\x1babc\x07123'
test = re.sub(b"\x1b.*\x07", '', test)
print(test)
except Exception as e:
print(e)
*quantifier is greedy: it tries to match as much as possible. For example, provided your bytestring is\x1babc\x07123\x07the result after substitution will be empty string. Adding?after the quantifier makes it perform the match in non-greedy or minimal fashion; as few characters as possible will be matched. (from docs.python.org/3/library/re.html)