This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes PatternSyntaxException ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "PatternSyntaxException ?" Watch "PatternSyntaxException ?" New topic
Author

PatternSyntaxException ?

Kartik Ruppa
Ranch Hand

Joined: Aug 28, 2002
Posts: 60
Hi,
I try to run the following and I get a java.util.regex.PatternSyntaxException.Thats because of '{'.Why does it give an error for this character.Can anybody explain me.
Thanks in advance!
Kartik
public class Test{
public static void main(String args[]){
String test="test{test1{tgrte";
String [] test1=test.split("{");
for(int i=0;i<test1.length;i++){
System.out.println("String is "+test1[i]);
}
}
}
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

The "{" is a meta-character in regexp.
Therefore you have to mask it...

...I guess.


http://home.arcor.de/hirnstrom/bewerbung
Kartik Ruppa
Ranch Hand

Joined: Aug 28, 2002
Posts: 60
Hi Stefan,
I tried the escape character...but unable to compile.
msg: illegal escape character
Any solution for this.
Thanks in advance,
Kartik
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
The code needs to be It is necessary to use double backslashes in string literals that represent regular expressions.
HTH
Nigel Browne
Kartik Ruppa
Ranch Hand

Joined: Aug 28, 2002
Posts: 60
Nigel,
That works.Thanks.
Kartik
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PatternSyntaxException ?