Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #83758

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

From Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de>
Subject Re: what would be the regular expression for null byte present in a string
Date 2015-01-14 15:35 +0100
References <39F9E8A5546B9448A82E55FBEBE3EC450BD029A5@SACMBXIP03.sdcorp.global.sandisk.com>
Newsgroups comp.lang.python
Message-ID <mailman.17722.1421246163.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 01/13/2015 02:40 PM, Shambhu Rajak wrote:
> I have a string that I get as an output of a command as:
>
> '\x01\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x00*10232ae8944a*\x02\x00\x00\x00\x00\x00\x00\x00\n'
>
> 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.
>
> Thanks,
>
> Shambhu
>

If the characters you need to keep always form a contiguous stretch, you 
can also use:

exclude = ''.join(chr(n) for n in range(32))
s_in.strip(exclude)

Wolfgang

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: what would be the regular expression for null byte present in a string Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2015-01-14 15:35 +0100

csiph-web