Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
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

Win a copy of The Software Craftsman this week in the Agile forum!
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: 62298

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

[Asking smart questions] [Bear's FrontMan] [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: 31680

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]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Have you tried LearnNowOnline?
subject: Pattern