Java String.split(regex) not working

java, string

Solution

You need to do something like this:

\\|

The reason is that in regular expression in order for "|" to be considered as "|" and not as a regex operator you need the "\". But in java you can't just write "\" in a string because that's a save operator in a string. So you have to do `\\`. Hope that explains it.

Problem

I want to split a string each time there's a `|` in it, but the `split` method only accepts a regex. The regex `|` splits the string after each letter, which is not what I want. Using `\u007C` does the same thing too. I tried using `\|`, but that just gives me: `Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )`.

Original source