Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pattern

 
Anup Om
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Why wouldn't this compile?


Is it not equivalent to creating a pattern '\' ?

Thanks for help in advance.

EDIT: I am very sorry for a misleading post. The above line of code compiles. But, throws an exception - java.util.regex.PatternSyntaxException: Unexpected internal error near index 1.
Thanks Bear Bibeault.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64822
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When reporting a compiler error, do you not think it'd be a good idea to include the error message?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out any regular expression tutorial regarding the backslash, then consider how Java treats backslashes in strings.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34371
345
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anoo Kota wrote:Is it not equivalent to creating a pattern '\' ?

Yes, but that Pattern isn't valid. It says the next character as special meaning and there is no next character.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic