posted 16 years ago
As Joanne said, | is a special character in regular expressions. It means choice. Therefore, || means "empty string or empty string or empty string", in other words: empty string.
Now you may think: that would lead to 36 empty strings, because there are only 36 characters: one empty string before each character. The magic here is, there is also an empty string at the end that matches. Hence 37.
You might want to extend your expression to "\\s*\\|\\|\\s*" to include the spaces (whitespace) as well. \s (unescaped) means all whitespace characters, so that includes spaces. The * means zero or more times, so this regex means: || with any number of whitespace characters before or after it.