Replace new line/return with space using regex

前端 未结 7 1778
醉梦人生
醉梦人生 2020-12-24 06:36

Pretty basic question for someone who knows.

Instead of getting from

\"This is my text. 

And here is a ne         


        
7条回答
  •  粉色の甜心
    2020-12-24 06:50

    Your regex is good altough I would replace it with the empty string

    String resultString = subjectString.replaceAll("[\t\n\r]", "");
    

    You expect a space between "text." and "And" right?

    I get that space when I try the regex by copying your sample

    "This is my text. "
    

    So all is well here. Maybe if you just replace it with the empty string it will work. I don't know why you replace it with \s. And the alternation | is not necessary in a character class.

提交回复
热议问题