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


Groups > comp.lang.python > #83757

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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'output': 0.05; 'string.': 0.05; 'subject:would': 0.07; 'string': 0.09; '8bit%:30': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:string': 0.09; "''.join(c": 0.16; 'fetch': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'shambhu': 0.16; 'subject: \n ': 0.16; 'subject:expression': 0.16; 'subject:regular': 0.16; 'wrote:': 0.18; 'command': 0.22; 'portion': 0.22; 'header:User-Agent:1': 0.23; 'replace': 0.24; 'sorry,': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'received:132': 0.31; 'subject:what': 0.31; 'anyone': 0.31; 'subject:the': 0.34; 'could': 0.34; 'but': 0.35; 'e.g.': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'behavior': 0.77; 'as:': 0.81; 'you:': 0.81
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
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 Wed, 14 Jan 2015 15:21:33 +0100
References <39F9E8A5546B9448A82E55FBEBE3EC450BD029A5@SACMBXIP03.sdcorp.global.sandisk.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host px1.ruf.uni-freiburg.de
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0
In-Reply-To <39F9E8A5546B9448A82E55FBEBE3EC450BD029A5@SACMBXIP03.sdcorp.global.sandisk.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.17721.1421245320.18130.python-list@python.org> (permalink)
Lines 24
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1421245320 news.xs4all.nl 2946 [2001:888:2000:d::a6]:38059
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:83757

Show key headers only | 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\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.
>

Sorry, no regex either, but depending on what exact behavior you need 
str.isprintable() or even str.isalnum() could be for you:

e.g.

s_in = 
'\x01\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x0010232ae8944a\x02\x00\x00\x00\x00\x00\x00\x00\n'
s_out = ''.join(c for c in s_in if c.isprintable())

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:21 +0100

csiph-web