<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Oct 28, 2014 at 4:02 AM, <span dir="ltr"><<a href="mailto:massi_srb@msn.com" target="_blank">massi_srb@msn.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi everyone,<br>
<br>
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 :-)<br>
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:<br>
<br>
newstring = re.sub(ur"""(?u)(\$\"[\s\w]+\")""", subst, oldstring)<br>
<br>
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".<br>
Can anyone help me to correct it?<br>
<br>
Thanks in advance!<br>
<span class=""><font color="#888888">--<br>
<a href="https://mail.python.org/mailman/listinfo/python-list" target="_blank">https://mail.python.org/mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br><div class="gmail_default" style="font-size:small">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.<br><br>[1] <a class="linkificator-ext" href="http://www.regular-expressions.info/examplesprogrammer.html" title="Linkificator: http://www.regular-expressions.info/examplesprogrammer.html">http://www.regular-expressions.info/examplesprogrammer.html</a><br></div><br></div></div>