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


Groups > comp.lang.python > #79849

Re: Regex substitution trouble

Date 2014-10-28 17:52 +0000
From MRAB <python@mrabarnett.plus.com>
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>
Newsgroups comp.lang.python
Message-ID <mailman.15264.1414518763.18130.python-list@python.org> (permalink)

Show all headers | 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