【发布时间】:2011-01-09 07:57:39
【问题描述】:
我想使用 python 的 re 模块从(大部分是有效的)JavaScript 中过滤掉(大部分是单行的)cmets。例如:
// this is a comment
var x = 2 // and this is a comment too
var url = "http://www.google.com/" // and "this" too
url += 'but // this is not a comment' // however this one is
url += 'this "is not a comment' + " and ' neither is this " // only this
我现在尝试了半个多小时,但没有任何成功。谁能帮帮我?
编辑 1:
foo = 'http://stackoverflow.com/' // these // are // comments // too //
编辑 2:
bar = 'http://no.comments.com/'
【问题讨论】:
-
此时,您应该考虑使用适当的解析器,而不是尝试破解正则表达式。
-
谢谢 Anon。如果我不能很快想出一个正则表达式,我会去找一个解析器。也许是蜘蛛猴?
标签: javascript python regex replace