• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Illegal Escape Character

 
Ranch Hand
Posts: 52
  • 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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[ July 14, 2008: Message edited by: sargunan Rswamy ]
 
Sargunan Rswamy
Greenhorn
Posts: 3
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't see the reply
 
Ranch Hand
Posts: 331
Python Ruby Ubuntu
  • 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
 
Ranch Hand
Posts: 71
  • 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>
 
please buy my thing and then I'll have more money:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!