Remove all empty lines

后端 未结 7 1518
误落风尘
误落风尘 2020-11-27 17:22

I thought that wasn\'t that hard to do, but I want to remove all empty lines (or lines just containing blanks and tabs in Java) with String.replaceAll.

My regex look

相关标签:
7条回答
  • 2020-11-27 18:17

    I don't know the syntax for regular expressions in Java, but /^\s*$[\n\r]{1,}/gm is the regex you're looking for.

    You probably write it like this in Java:

    s = s.replaceAll("(?m)^\\s*$[\n\r]{1,}", "");
    

    I tested it with JavaScript and it works fine.

    0 讨论(0)
提交回复
热议问题