1

Im trying to find a regex with whom i can split a certain Text by any possible new character. I know that i could use "\\r?\\n" as regex which would work in almost every case and for almost every platform.

But today i faced a problem where im receiving a String from a Swing component which can't be splitted with this regex like i was hoping.

If the String is printed into the eclipse console i can see that there are linebreaks but probably not using \r\n for linebreaks (dont know yet which special character it is actually, i can see only a the newlines in eclipse console and didn't find a way to display the unicode character for example).

After searching a while for a solution how i can determine these newlines i found another regex which is able to find these line breaks:

Matcher matcher = Pattern.compile("^(.*)$", Pattern.MULTILINE).matcher(>>String<<<);

Now im searching for a way how to combine these regex's or use just one expression to find just any newline.

Anyone a idea?

I found the reason:

My Text had some trailing new lines and i was using the wrong String split function. Instead of using

text.split("\\r?\\n")

i had to use

text.split("\\r?\\n", -1)

to get all lines...

StephanM
  • 1,350
  • 2
  • 24
  • 50

0 Answers0