File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PatternSyntaxException ?

 
Kartik Ruppa
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1923
Linux Postgres Database Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "{" is a meta-character in regexp.
Therefore you have to mask it...

...I guess.
 
Kartik Ruppa
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 682
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nigel,
That works.Thanks.
Kartik
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic