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


Groups > comp.lang.python > #71511

Re: Why isn't my re.sub replacing the contents of my MS Word file?

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'syntax': 0.04; 'binary': 0.07; 'subject:file': 0.07; 'string': 0.09; 'interpreted': 0.09; 'literal': 0.09; 'so?': 0.09; 'subject:Why': 0.09; 'missed': 0.12; "'-'": 0.16; "(it's": 0.16; 'chunks': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'hex': 0.16; 'hexadecimal': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'stored.': 0.16; 'symbols': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'file,': 0.19; 'header:User-Agent:1': 0.23; 'byte': 0.24; 'controlling': 0.24; 'replace': 0.24; 'file.': 0.24; 'this:': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; '13,': 0.31; "d'aprano": 0.31; 'doc': 0.31; 'long.': 0.31; 'steven': 0.31; 'file': 0.32; 'thanks!': 0.32; 'regular': 0.32; 'text': 0.33; 'open': 0.33; 'noticed': 0.34; 'subject:the': 0.34; 'created': 0.35; 'something': 0.35; 'editor': 0.35; 'there': 0.35; 'subject:?': 0.36; 'similar': 0.36; 'so,': 0.37; 'operating': 0.37; 'two': 0.37; 'being': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'most': 0.60; 'identify': 0.61; "you're": 0.61; 'email addr:gmail.com': 0.63; 'within': 0.65; 'characters,': 0.84; 'parser,': 0.84; 'dirty': 0.93
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=etNRz+ZX c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=1oDRhzKAKukA:10 a=VcfSm_tTUzkA:10 a=ihvODaAuJD4A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=pGLkceISAAAA:8 a=LFaz6YVMLxP1f1CIVv8A:9 a=QEXdDO2ut3YA:10 a=MSl-tDqOz04A:10
X-AUTH mrabarnett:2500
Date Tue, 13 May 2014 21:26:51 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Why isn't my re.sub replacing the contents of my MS Word file?
References <ea305e19-be61-469b-8a15-0753406f8476@googlegroups.com> <536d6f08$0$29980$c3e8da3$5496439d@news.astraweb.com> <6caea381-c765-41e7-9135-d5a0d60b7f42@googlegroups.com> <537222d8$0$29980$c3e8da3$5496439d@news.astraweb.com> <63051425-ec42-45b4-8a9e-53001625f32a@googlegroups.com>
In-Reply-To <63051425-ec42-45b4-8a9e-53001625f32a@googlegroups.com>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
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.9980.1400012820.18130.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1400012820 news.xs4all.nl 2940 [2001:888:2000:d::a6]:52919
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:71511

Show key headers only | View raw


On 2014-05-13 20:01, scottcabit@gmail.com wrote:
> On Tuesday, May 13, 2014 9:49:12 AM UTC-4, Steven D'Aprano wrote:
>>
>> You may have missed my follow up post, where I said I had not noticed you
>> were operating on a binary .doc file.
>>
>> If you're not willing or able to use a full-blown doc parser, say by
>> controlling Word or LibreOffice, the other alternative is to do something
>> quick and dirty that might work most of the time. Open a doc file, or
>> multiple doc files, in a hex editor and *hopefully* you will be able to
>> see chunks of human-readable text where you can identify how en-dashes
>> and similar are stored.
>
>    I created a .doc file and opened it with UltraEdit in binary (Hex) mode. What I see is that there are two characters, one for ndash and one for mdash, each a single byte long. 0x96 and 0x97.
>    So I tried this: fStr = re.sub(b'\0x96',b'-',fStr)
>
>    that did nothing in my file. So I tried this: fStr = re.sub(b'0x97',b'-',fStr)
>
>    which also did nothing.
>    So, for fun I also tried to just put these wildcards in my re.findall so I added |Part \0x96|Part \0x97    to no avail.
>
>    Obviously 0x96 and 0x97 are NOT being interpreted in a re.findall or re.sub as hex byte values of 96 and 97 hexadecimal using my current syntax.
>
>    So here's my question...if I want to replace all ndash  or mdash values with regular '-' symbols using re.sub, what is the proper syntax to do so?
>
>    Thanks!
>
0x96 is a hexadecimal literal for an int. Within a string you need \x96
(it's \x for 2 hex digits, \u for 4 hex digits, \U for 8 hex digits).

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


Thread

Why isn't my re.sub replacing the contents of my MS Word file? scottcabit@gmail.com - 2014-05-09 12:51 -0700
  Re: Why isn't my re.sub replacing the contents of my MS Word file? MRAB <python@mrabarnett.plus.com> - 2014-05-09 21:03 +0100
    Re: Why isn't my re.sub replacing the contents of my MS Word file? scottcabit@gmail.com - 2014-05-09 13:46 -0700
  Re: Why isn't my re.sub replacing the contents of my MS Word file? Chris Angelico <rosuav@gmail.com> - 2014-05-10 06:08 +1000
  Re: Why isn't my re.sub replacing the contents of my MS Word file? Tim Chase <python.list@tim.thechases.com> - 2014-05-09 15:09 -0500
    Re: Why isn't my re.sub replacing the contents of my MS Word file? scottcabit@gmail.com - 2014-05-09 13:49 -0700
      Re: Why isn't my re.sub replacing the contents of my MS Word file? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-05-10 00:31 +0000
  Re: Why isn't my re.sub replacing the contents of my MS Word file? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-05-10 00:12 +0000
    Re: Why isn't my re.sub replacing the contents of my MS Word file? scottcabit@gmail.com - 2014-05-12 10:35 -0700
      Re: Why isn't my re.sub replacing the contents of my MS Word file? Rustom Mody <rustompmody@gmail.com> - 2014-05-12 20:00 -0700
      Re: Why isn't my re.sub replacing the contents of my MS Word file? Dave Angel <davea@davea.name> - 2014-05-12 17:15 -0400
      Re: Why isn't my re.sub replacing the contents of my MS Word file? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-05-13 13:49 +0000
        Re: Why isn't my re.sub replacing the contents of my MS Word file? Chris Angelico <rosuav@gmail.com> - 2014-05-13 23:55 +1000
        Re: Why isn't my re.sub replacing the contents of my MS Word file? scottcabit@gmail.com - 2014-05-13 12:01 -0700
          Re: Why isn't my re.sub replacing the contents of my MS Word file? MRAB <python@mrabarnett.plus.com> - 2014-05-13 21:26 +0100
            Re: Why isn't my re.sub replacing the contents of my MS Word file? wxjmfauth@gmail.com - 2014-05-13 23:12 -0700
              Re: Why isn't my re.sub replacing the contents of my MS Word file? alister <alister.nospam.ware@ntlworld.com> - 2014-05-14 13:21 +0000
            Re: Why isn't my re.sub replacing the contents of my MS Word file? scottcabit@gmail.com - 2014-05-14 07:40 -0700
  Re: Why isn't my re.sub replacing the contents of my MS Word file? Rustom Mody <rustompmody@gmail.com> - 2014-05-09 21:22 -0700
    Re: Why isn't my re.sub replacing the contents of my MS Word file? wxjmfauth@gmail.com - 2014-05-10 00:11 -0700
      Re: Why isn't my re.sub replacing the contents of my MS Word file? Tim Golden <mail@timgolden.me.uk> - 2014-05-10 09:49 +0100

csiph-web