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


Groups > comp.lang.python > #79840

Re: Regex substitution trouble

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <wingusr@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'string.': 0.05; 'string': 0.09; 'skip:$ 20': 0.09; 'skip:$ 30': 0.09; 'skip:$ 40': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'advance!': 0.16; 'backslash,': 0.16; 'expressions,': 0.16; 'occurences': 0.16; 'substitute': 0.16; 'think.': 0.16; ':-)': 0.16; 'language': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'trying': 0.19; 'everyone,': 0.19; 'programming': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; '[1]': 0.29; 'am,': 0.29; 'character': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'anyone': 0.31; 'class': 0.32; 'regular': 0.32; 'another': 0.32; 'url:python': 0.33; 'could': 0.34; 'problem': 0.35; 'common': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'url:listinfo': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'should': 0.36; 'skip:& 10': 0.38; 'handle': 0.38; 'sure': 0.39; 'url:mail': 0.40; 'solve': 0.60; 'here': 0.66; 'skip:r 30': 0.69; 'url:info': 0.73; 'carefully': 0.74; 'to:addr:msn.com': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=u2BZgkNPWexQSn8wkUZ0x7UJgC4mL96wYXpl4d7W2w8=; b=ZGhpxUFWf/+soab68aHxKTKJEc4n1C6VtaMmMJPtEBsBjUy7185V/iFymN4OcsNP0K 96fBRZhHhcsoYex6rLBT6EX9eQ42JpIfA6hsSeH8rgxFLVp/I+i2eT7Qn2i6NQE3He7s e4jRe0SzT3sdnIs97MqOoaSj7JcR/ka6c+zbifdQWNqWrcsaRstci/vISQDgMranOyf3 io9hAFZZu9+65bj1jWoTAU2+vL4muOTp3TctSwBTuSFOneT2hFG9X7YHhv64ltX+g8vx Qd2lDqVJPpRvuS3jbTJAxB4pWuDjYuHIoKQjI6x2ujkImDEvtdSTjYPvcdV9vPkaYyQ8 a4Hg==
X-Received by 10.180.11.66 with SMTP id o2mr4947289wib.22.1414502742006; Tue, 28 Oct 2014 06:25:42 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <8c1c1b7f-d121-4f3d-adf9-8262ddd8f102@googlegroups.com>
References <8c1c1b7f-d121-4f3d-adf9-8262ddd8f102@googlegroups.com>
From TP <wingusr@gmail.com>
Date Tue, 28 Oct 2014 06:25:00 -0700
Subject Re: Regex substitution trouble
To massi_srb@msn.com
Content-Type multipart/alternative; boundary=001a11c26a0878a33105067b95e4
Cc "python-list@python.org" <python-list@python.org>
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.15261.1414502744.18130.python-list@python.org> (permalink)
Lines 74
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1414502744 news.xs4all.nl 2870 [2001:888:2000:d::a6]:53195
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:79840

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Tue, Oct 28, 2014 at 4:02 AM, <massi_srb@msn.com> wrote:

> Hi everyone,
>
> I'm not really sure if this is the right place to ask about regular
> expressions, but since I'm usin python I thought I could give a try :-)
> Here is the problem, I'm trying to write a regex in order to substitute
> all the occurences in the form $"somechars" with another string. This is
> what I wrote:
>
> newstring = re.sub(ur"""(?u)(\$\"[\s\w]+\")""", subst, oldstring)
>
> This works pretty well, but it has a problem, I would need it also to
> handle the case in which the internal string contains the double quotes,
> but only if preceeded by a backslash, that is something like
> $"somechars_with\\"doublequotes".
> Can anyone help me to correct it?
>
> Thanks in advance!
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Carefully reading the Strings section of "Example Regexes to Match Common
Programming Language Constructs" [1] should (with a bit of effort), solve
your problem I think. Note the use of the negated character class for one
thing.

[1] http://www.regular-expressions.info/examplesprogrammer.html

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