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!

String.replaceAll(java.lang.String regex, java.lang.String replacement)

807597Sep 21 2002 — edited May 30 2005
Hi folks,

I seem to be running into a little bit of trouble with the String.replaceAll() method.

I have a piece of code that does the following:

     System.out.println(outerLine.replaceAll("{procName}", procName));
outerLine is a String object that is the result of a BufferedReader.readLine() method. The code compiles okay, but when I execute the program, however, I run into an illegal repetition exception. This is the explicit error message:
Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal repetition
{user}
        at java.util.regex.Pattern.error(Pattern.java:1472)
        at java.util.regex.Pattern.closure(Pattern.java:2473)
        at java.util.regex.Pattern.sequence(Pattern.java:1597)
        at java.util.regex.Pattern.expr(Pattern.java:1489)
        at java.util.regex.Pattern.compile(Pattern.java:1257)
        at java.util.regex.Pattern.<init>(Pattern.java:1013)
        at java.util.regex.Pattern.compile(Pattern.java:760)
        at java.lang.String.replaceAll(String.java:1706)
        at TestObject.<init>(TestObject.java:36)
        at TestObject.main(TestObject.java:57)
The line that is being processed at this point is:
     User {user} will the required to provide more details.  {user}, please ...
I would be grateful for any input into why the error occurs.

Thanks in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 27 2005
Added on Sep 21 2002
3 comments
882 views