Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Illegal repetition error - .replaceAll()

807601May 3 2008 — edited May 4 2008
Hi, im using string.replaceAll() to get rid of a load of random text from a file, however i keep getting the exception java.util.regex.PatternSyntaxException: Illegal repetition( and where its all gone wrong)

I think its because it doesnt like me doing the 'cleanString = cleanString' bit, can I put all the expressions into 1? The only other way i can think is to have loads of variables and that would just suck.
for(;;) 
{
    while (loopCount<=84)
    {
        String testString = reader.readLine();
        if (testString.equalsIgnoreCase(""))
        {
            testString = reader.readLine();
        }
        cleanString = testString.replaceAll("@", "");
        cleanString = cleanString.replaceAll("{", "");
        cleanString = cleanString.replaceAll("}", "");
        cleanString = cleanString.replaceAll("=", "");
				
        tokenizeThis = new StringTokenizer(cleanString);
        word = tokenizeThis.nextToken();
        if (word.equalsIgnoreCase("name"))
        {
            cleanString = cleanString.replaceAll("name", "");
            cleanString = cleanString.replaceAll(" ", "");
						
            captainList[loopCount] = cleanString;
            loopCount++;
            System.out.println("Captain  " + cleanString);
        }
        else
        {
            playerList[loopCount][loopCount2] = cleanString;
            loopCount2++;
            System.out.println("Player " + cleanString);
            if (loopCount2>=6)
            {
                loopCount2 = 0;
            }
        }
    }
}
A section of the file im trying to read:
@ {
name = "john jackson",
steve smith],
thomas adams],
}

Hope you can help, been working on this for a while, thank you very much in advance!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 1 2008
Added on May 3 2008
4 comments
969 views