what would be the regular expression for null byte present in a string

Peter Otten __peter__ at web.de
Tue Jan 13 15:41:51 CET 2015

Shambhu Rajak wrote:

> I have a string that I get as an output of a command as:
> I want to fetch '10232ae8944a' from the above string.
> I want to find a re pattern that could replace all the \x01..\x0z to be
> replace by empty string '',  so that I can get the desired portion of
> string
> Can anyone help me with a working regex for it.

I think you want the str.tranlate() method rather than a regex. 

Assuming you are using Python 2:

>>> delenda = "".join(map(chr, range(32)))
>>> identity = "".join(map(chr, range(256)))

With Python3:

>>> mapping = dict.fromkeys(range(32))

More information about the Python-list mailing list