Originally posted by Keith Lynn:
You have to escape symbols that have special meaning if you want to use the symbol without the meaning.
Exactly. In a regular expression, the period is a "construct" with a special meaning of "match any character" (so
every character in your String was a delimiter, and you ended up with nothing in between). See the
Pattern link I posted above for other constructs.
By putting \\ in front of the period, you're saying, "I want this to be a
literal period, with no special meaning."
As for why it's a
double blackslash, note the following from the Pattern link posted above...
Backslashes within string literals in Java source code are interpreted as required by the Java Language Specification as either Unicode escapes or other character escapes. It is therefore necessary to double backslashes in string literals that represent regular expressions to protect them from interpretation by the Java bytecode compiler.
[ February 23, 2006: Message edited by: marc weber ]