• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5653
  • Last Modified:

Exception: java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 0

Dear expert,

I split a string Query = PERSON*YEAR*DATE

String Query = PERSON*YEAR*DATE;
String[] result = null;
String splitPattern = "*";
result = Query.split(splitPattern);
if (result != null) {
     String str = "result 1 = " + result[1];
    System.println(str);
} else {
   System.println("wrong input");
}

But I have error .... Exception: java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 0

I have searched a lot of sites and can't find any solution. Please help!

0
Wonder19
Asked:
Wonder19
1 Solution
 
suprapto45Commented:
Hi,

Should not the Query be
String Query = "PERSON*YEAR*DATE";

David
0
 
CEHJCommented:
>>String splitPattern = "*";

should be

String splitPattern = "\\*";

as the asterisk is a reserved character in regex
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
Change

>>String splitPattern = "\*";

check out

http://www.codeguru.com/forum/showthread.php?s=&threadid=292394
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
sciuriwareCommented:
String[] result = null;        // No need to initialise it now.

String splitPattern = "*";  // Not what you want:                      "\\*";

;JOOP!
0
 
sciuriwareCommented:
Again beaten!

Btw."    "\*" is wrong : compilation error: bad escape.


;JOOP!
0
 
CEHJCommented:
:-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now