Originally posted by Lucky J Verma:
... But i read for \d we have to use \\d as ,compiler thinks \d is some escape sequence.
but here ,on command line ,dont we reqire 1 more slash. "\\d"
The escape sequences for Java Strings are listed under
JLS - 3.10.6 Escape Sequences for Character and String Literals.
For example, in a String literal, \b is an escape sequence interpreted as a backspace. However, in a regex
Pattern, \b represents a
word boundary. So to prevent \b from being interpreted as a backspace in a regex Pattern, an additional escape is required: \\b.
However, note that \d is
not listed as an escape for a String literal. So when used to represent any digit in a regex Pattern, it does
not require an additional escape.
(Also see java.util.regex.Pattern in the
API.)