Java regex: newline + white space

前端 未结 4 1898
梦如初夏
梦如初夏 2021-01-17 12:58

should be simple, but I\'m going crazy with it.

Given a text like:

line number 1
line number 2
 line number 2A
line number 3
 line number 3A
 line n         


        
相关标签:
4条回答
  • 2021-01-17 13:12
    String res = orig.replaceAll("[\\r\\n]+\\s", "");
    
    0 讨论(0)
  • 2021-01-17 13:14

    Perhaps to make it cross-platform:

    String pattern = System.getProperty("line.separator") + " ";
    string.replaceAll(pattern, "");
    
    0 讨论(0)
  • 2021-01-17 13:15

    yourString.replaceAll("\n ", " "); this wont help?

    0 讨论(0)
  • 2021-01-17 13:20

    "\n " This is should do the trick if you are in Unix LF mode. For DOS like you need to match CRLF "\r\n ". Did check with RegexBuddy looking fine.

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