Why this code is executing successfully, when I execut it as: >java Mogli "\d" ?
I was expecting some problem due to illegal escape character in the above code, but it didn't actually..
And I thought so as the following code gives an error "illegal escape character" at compile time :
Now, where am I getting wrong...
\d is an illegal escape sequence for the compiler but the regular expression engine recognizes it. So to get past the compiler you use \\d but the regex engine will still treat it as \d. When you pass the pattern as a command line argument, you don't have to worry about the compiler thus passing \d also works...