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!

Wonder19Asked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
>>String splitPattern = "*";

should be

String splitPattern = "\\*";

as the asterisk is a reserved character in regex
0
 
suprapto45Commented:
Hi,

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

David
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
Change

>>String splitPattern = "\*";

check out

http://www.codeguru.com/forum/showthread.php?s=&threadid=292394
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.