[Tutor] RE module is working ?

Karim karim.liateni at free.fr
Fri Feb 4 20:34:26 CET 2011


On 02/04/2011 11:26 AM, Peter Otten wrote:
> Karim wrote:
>
>> That is not the thing I want. I want to escape any " which are not
>> already escaped.
>> The sed regex  '/\([^\\]\)\?"/\1\\"/g' is exactly what I need (I have
>> made regex on unix since 15 years).
> Can the backslash be escaped, too? If so I don't think your regex does what
> you think it does.
>
> r'\\\"' # escaped \ followed by escaped "
>
> should not be altered, but:
>
> $ echo '\\\"' | sed 's/\([^\\]\)\?"/\1\\"/g'
> \\\\" # two escaped \ folloed by a " that is not escaped
>
>

By the way you are right:

I changed an I added sed command for the ' "" ':

karim at Requiem4Dream:~$ echo 'prima " "' | sed -e 
's/""/\\"\\"/g;s/\([^\]\)"/\1\\"/g'
prima \" \"
karim at Requiem4Dream:~$ echo 'prima ""' | sed -e 
's/""/\\"\\"/g;s/\([^\]\)"/\1\\"/g'
prima \"\"
karim at Requiem4Dream:~$ echo 'prima "Ich Karim"' | sed -e 
's/""/\\"\\"/g;s/\([^\]\)"/\1\\"/g'
prima \"Ich Karim\"
karim at Requiem4Dream:~$ echo 'prima "Ich Karim"' | sed -e 
's/""/\\"\\"/g;s/\([^\]\)"/\1\\"/g'
prima \"Ich Karim\"

Sorry, for the incomplete command. You pointed it out, many thanks Peter!

Regards
Karim


> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list