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: 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 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> In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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 '"'.