2009/7/29 Nobody <nob...@nowhere.com>:
>> The output should be something like
>> <script>document.write("hellooooo my name is  21c";)</script>
>
> import re
> r = re.compile(r'"\s*\+\s*"')
> s = r'''<script>document.write("h" +"e"+ "ll"+ "ooooo"+ " m" +"y"+" n"+"ame"+
> " is  "+"21c";)</script>'''
> r.sub('', s)
>

Nobody's solution is good.
here is more complicated solution, just for regex practice :-)

>>> s = '<script>document.write("h" +"e"+ "ll"+ "ooooo"+ " m" +"y"+" n"+"ame"+" 
>>> is  "+"21c";)</script>'
>>> new_s = re.sub(r'(?<=")(.+)(?=")', ''.join(re.findall(r'"([^"]+)"', s)), s)
>>> new_s
'<script>document.write("hellooooo my name is  21c";)</script>'
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to