Regex substitution trouble

MRAB python at mrabarnett.plus.com
Tue Oct 28 18:52:32 CET 2014


On 2014-10-28 12:28, massi_srb at 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 '"'.




More information about the Python-list mailing list