• Post Reply Bookmark Topic Watch Topic
  • New Topic

StringPattern exception  RSS feed

 
James Jiang
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey:
I got an error: java.util.regex.PatternSyntaxException: Unexpected internal error near index 1 when i run the codes below:
public void testGetResult(){
String pattern="\\";
String target="james\\jiang";
//getResult(target,pattern) calls String.split(pattern) and returns
//the first element of the string array.
String result=StringPattern.getResult(target,pattern);
assertEquals("james",result);
}
what's wrong with pattern:"\\".Thanks for your patience.
 
Campbell Ritchie
Marshal
Posts: 56553
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think, that you have escaped the \ to a \ which means the compiler is trying to escape J. Try \\\\ instead of \\ if you want a \ to appear.
 
James Jiang
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem solved, thank you Campbell.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!