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

Thomas 'PointedEars' Lahn PointedEars at web.de
Wed Jan 14 14:52:06 CET 2015


Peter Otten wrote:

> 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\x0010232ae8944a\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.
> 
> I think you want the str.tranlate() method rather than a regex.

Another possibility, but given the length of the list probably not the most 
efficient one.  Aside from re and this one, here is another (tested with 
Python 3.4.2):

  filtered = ''.join(filter(lambda ch: ord(ch) > 0x0f, s))

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.



More information about the Python-list mailing list