Re: [问题] 请问怎么找出注解

楼主: PurpleCrow (17868)   2012-08-15 14:15:11
※ 引述《ccbruce (今、そこに いる仆)》之铭言:
: 我是用.net的Regex的
: 现在想要写一个可以删掉所有C/C++ Style comment的程式
: 而且不可以删掉包在双引号内的类似注解的字串
: 现在用的pattern为:
: (?!")((//.*)|((?s)(/\*.*?\*/)))(?<!")
: 虽然可以找出单行跟多行注解, 不过包在字串里的类似注解的字串也一起被找出来了
: 请问有什么解决的方法吗?
: 正常:
: //comment
: "aaa" //comment
: /*
: comment
: */
: "aaa" /*
: comment
: */
: 异常:
: "//not comment"
: "/*not comment"
总算看懂了
编号一下
//comment1
"aaa" //comment2
/*
comment3
*/
"aaa" /*
comment4
*/
"//not comment5"
"/*not comment6"
(?<!")(//[^\n]+|/\*.*?\*/)

//comment1
//comment2
/*
comment3
*/
/*
comment4
*/
是这个意思吗?

Links booklink

Contact Us: admin [ a t ] ucptt.com