Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83757 > unrolled thread
| Started by | Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> |
|---|---|
| First post | 2015-01-14 15:21 +0100 |
| Last post | 2015-01-14 15:21 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
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
| From | Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> |
|---|---|
| Date | 2015-01-14 15:21 +0100 |
| Subject | Re: what would be the regular expression for null byte present in a string |
| Message-ID | <mailman.17721.1421245320.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web