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


Groups > comp.lang.python > #79849

Re: Regex substitution trouble

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'modified': 0.07; 'skip:u 30': 0.07; 'skip:$ 30': 0.09; 'way:': 0.09; 'chris,': 0.16; 'different;': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'guru': 0.16; 'match:': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'help!': 0.26; 'post': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; "i'm": 0.30; 'work.': 0.31; 'reply.': 0.31; "skip:' 10": 0.31; "skip:' 40": 0.31; 'something': 0.35; 'received:84': 0.35; 'but': 0.35; 'surely': 0.36; 'thanks': 0.36; 'similar': 0.36; 'ahead': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'absolutely': 0.87
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=ceBcrxzM c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=aoAcgTy3oA8A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=AAvYLDLOAAAA:8 a=_OqtH6hifwh2Tjg6jnEA:9 a=QEXdDO2ut3YA:10
X-AUTH mrabarnett:2500
Date Tue, 28 Oct 2014 17:52:32 +0000
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Regex substitution trouble
References <8c1c1b7f-d121-4f3d-adf9-8262ddd8f102@googlegroups.com> <mailman.15258.1414495491.18130.python-list@python.org> <f65a31e0-0c8e-4f6d-808f-7a9468c2c1e2@googlegroups.com>
In-Reply-To <f65a31e0-0c8e-4f6d-808f-7a9468c2c1e2@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.15264.1414518763.18130.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1414518763 news.xs4all.nl 2909 [2001:888:2000:d::a6]:50538
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:79849

Show key headers only | View raw


On 2014-10-28 12:28, massi_srb@msn.com wrote:
> Hi Chris, thanks for the reply. I tried to use look ahead assertions, in particular I modified the regex this way:
>
> newstring = re.sub(ur"""(?u)(\$\"[\s\w(?<=\\)\"]+\")""", subst, oldstring)
>
> but it does not work. I'm absolutely not a regex guru so I'm surely missing something. The strings I'm dealing with are similar to formulas, let's say something like:
>
> '$["simple_input"]+$["messed_\\"_input"]+10'
>
> Thanks for any help!
>
Your original post said you wanted to match strings like:

$"somechars_with\\"doublequotes".

This regex will do that:

ur'\$"[^"\\]*(?:\\.[^"\\]*)*"'

However, now you say you want to match:

'$["simple_input"]'

This is different; it has '[' immediately after the '$' instead of '"'.

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


Thread

Regex substitution trouble massi_srb@msn.com - 2014-10-28 04:02 -0700
  Re: Regex substitution trouble Chris Angelico <rosuav@gmail.com> - 2014-10-28 22:24 +1100
    Re: Regex substitution trouble massi_srb@msn.com - 2014-10-28 05:28 -0700
      Re: Regex substitution trouble Chris Angelico <rosuav@gmail.com> - 2014-10-28 23:59 +1100
      Re: Regex substitution trouble MRAB <python@mrabarnett.plus.com> - 2014-10-28 17:52 +0000
  Re: Regex substitution trouble TP <wingusr@gmail.com> - 2014-10-28 06:25 -0700
  Re: Regex substitution trouble Tim <jtim.arnold@gmail.com> - 2014-10-28 09:38 -0700
  Re: Regex substitution trouble Cameron Simpson <cs@zip.com.au> - 2014-10-29 13:14 +1100
  Re: Regex substitution trouble Eugene <hexumg@gmail.com> - 2014-11-05 13:44 +0300

csiph-web