File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Illegal Escape Character

 
Faber Siagian
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

I have a problem to understand this case :

import java.util.regex.*;



Compilation should be failed at line 7 because the presence of an Illegal escape character.
But if i change the program :

...
Pattern p = Pattern.compile(args[0]);
...

then i run the application by invoking command line :

java Regex "\d"

the application runs successfully, but actually i expect the compilation failed at line 7. Someone please explain this to me.
 
Sargunan Rswamy
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[ July 14, 2008: Message edited by: sargunan Rswamy ]
 
Sargunan Rswamy
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try This





import java.util.regex.*;


[ July 14, 2008: Message edited by: sargunan Rswamy ]
 
Faber Siagian
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't see the reply
 
Sumit Bisht
Ranch Hand
Posts: 331
Python Ruby Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your program is working fine!
You were expecting a RunTime Exception but your JVM decided that it was ok to go by a single \
Please note that this behaviour is not guaranteed in all JVMs.
For more, please see pg. 482 of k&b scjp 5 study guide.
Also as mentioned there, the command-line behaviour is not in the exam
 
Madhukar Ojha
Ranch Hand
Posts: 71
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Faber ,

You have to make only one change if you are running this program
on Windows.

<blockquote>code:
<pre name="code" class="core">
Pattern p = Pattern.compile("\\d");
</pre>
</blockquote>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic