On Jan 26, 3:54 am, "Frank Potter" <[EMAIL PROTECTED]> wrote: > > I'm very sorry because I was in a hurry when I post this thread. > I'll post again my code here: > [CODE] > import re > > f=open("show_btchina.user.js","r").read() > f=unicode(f,"utf8") > > r=re.compile(ur"//[^\r\n]+$", re.UNICODE|re.VERBOSE) > f_new=r.sub(ur"",f) > > open("modified.js","w").write(f_new.encode("utf8")) > [/CODE] >
Here's a pyparsing version that will stay clear of '//' inside quoted strings. (untested) -- Paul from pyparsing import javaStyleComment, dblQuotedString f=open("show_btchina.user.js","r").read() f=unicode(f,"utf8") commentFilter = Suppress( javaStyleComment ).ignore( dblQuotedString ) f_new= commentFilter.transformString(f) open("modified.js","w").write(f_new.encode("utf8")) -- http://mail.python.org/mailman/listinfo/python-list