21grams
V2EX  ›  Java

有啥简单的方法可以过滤掉文本文件中的所有注释?

  •  
  •   21grams · Jun 5, 2015 via Android · 4996 views
    This topic created in 4184 days ago, the information mentioned may be changed or developed.
    注释以//或#开头。懒得自己写了,有没有现成的可以用?
    9 replies  •  2015-06-06 00:39:17 +08:00
    kokutou
    kokutou
    Jun 5, 2015 via Android
    1
    方法太简单太多了了,懒的写了,看楼下有没有现成的给lz用用。
    oott123
    oott123
    Jun 5, 2015 via Android
    2
    sed
    l12ab
    l12ab
    Jun 5, 2015
    3
    各种tidy
    cloud107202
    cloud107202
    Jun 5, 2015
    4
    https://github.com/liyuntao/JavaCommentRemover

    以前写的,马马虎虎能用
    lunaticus7
    lunaticus7
    Jun 5, 2015
    5
    楼上说的sed,+1
    wizardoz
    wizardoz
    Jun 5, 2015
    6
    如果只是//和#开头的注释,简直太简单了。

    sed 就可以

    多行注释就稍微复杂一些了
    Theo14
    Theo14
    Jun 5, 2015
    7
    我在看配置文件的时候喜欢用这个命令
    grep -v -E "^$|^#" xxx.txt
    供参考
    flowfire
    flowfire
    Jun 5, 2015
    8
    ......sublime text正则替换。。。
    yuedingwangji
    yuedingwangji
    Jun 6, 2015
    9
    vim不是可以实现么 , 1,500s/^/ /g 这个表示取消1-500行行首的注释
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2366 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 64ms · UTC 13:31 · PVG 21:31 · LAX 05:31 · JFK 08:31
    ♥ Do have faith in what you're doing.