How to use String#split with a backslash character?

java, regex, split, string

Solution

In regex-land, a `\` is an escape character, so to obtain a literal `\` we need to escape it: `\\`. However, in Java strings, `\` is also an escape character, so we need to escape each `\` a second time, resulting in `\\\\`. Therefore, this is what you want:

str.split("\\\\")

Problem

I would like to split this string: ``` C:\RCOUNT2013\2013_Extracted\Weekly ODEN Notices Report.12-28-2013.2013-12-29 07-20-51.pdf.log.0 ``` on the `\`. What would the regex be? ``` string.split("\\ \") // ? ```

Original source