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