我想删除Java代码中的注释。我见过很多例子,但每个都写错了。Java - Regex - 删除评论
这里是例子的代码:
String somestring = "http://google.com"; // "//google.com";" is going to be removed
又如:
get.setHeader("Accept", "*/*"); // "/*");" and later is going to be removed too
但我想正确的正则表达式,处理这些案件
我想: http://ostermiller.org/findcomment.html Regular expression to remove comment 和其他流行的例子
应该处理常见的情况:
somemethod();//it should be removed
somemethod(); /* some comment that may end on other line */
但应办理等情况:
String somestring = "http://google.com"; // url shouldn't be touched
get.setHeader("Accept", "*/*"); // "*/*" shouldn't be touched too
你试过了什么? – 2015-02-09 13:37:19
您的预期产出是? – 2015-02-09 13:38:00
阅读你提供的链接的底部段落:*解决这个问题的方法是编写正则表达式来描述每个可能的更大的元素,找到它们,决定每种元素的类型,并丢弃那些不是注释。有些工具称为词法分析器或标记器,可以帮助完成此任务。* – aioobe 2015-02-09 13:42:12