File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Pattern " Watch "Pattern " New topic


Anup Om
Ranch Hand

Joined: Dec 30, 2009
Posts: 62

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

Joined: Jan 10, 2002
Posts: 63866

When reporting a compiler error, do you not think it'd be a good idea to include the error message?

[Asking smart questions] [About Bear] [Books by Bear]
David Newton

Joined: Sep 29, 2008
Posts: 12617

Check out any regular expression tutorial regarding the backslash, then consider how Java treats backslashes in strings.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33130

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Pattern
It's not a secret anymore!