Paul McGuire
2007-01-26 17:53:04 UTC
I'm very sorry because I was in a hurry when I post this thread.
[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[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]
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"))