匹配C樣式多行注釋的Regex我有一根繩子。String src = "How are things today /* this is comment *\*/ and is your code /*\* this is another comment */ working?"我想移除/* this is comment *\*/和/** this is another comment */從src繩子。我試圖使用regex,但由于經(jīng)驗不足而失敗了。
3 回答

jeck貓
TA貢獻1909條經(jīng)驗 獲得超7個贊
試試這個:
(//[^\n]*$|/(?!\\)\*[\s\S]*?\*(?!\\)/)
如果要排除“中包含的部分,請使用:
(\"[^\"]*\"(?!\\))|(//[^\n]*$|/(?!\\)\*[\s\S]*?\*(?!\\)/)
第一個捕獲組標識所有“部分”,第二個捕獲組給出注釋(包括單行和多行)。
添加回答
舉報
0/150
提交
取消