21grams
V2EX  ›  Java

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

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

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

    sed 就可以

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