Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8296437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:59:35+00:00 2026-06-08T14:59:35+00:00

look at the following code: String comment = 1)FCR pick up in Hong Kong2)Local

  • 0

look at the following code:

String comment = "1)FCR pick up in Hong Kong2)Local charges will be paiy in Hong Kong & in HK$.3)Booking:virginiawong@fahkco.com.hk4)FCR&DOC:emilywu@fahkco.com.hkTel:00852-23021977Fax:00852-2730217Transaction865320submittedVirginiaWong(T1281954U005) and Status is INCMP  on 10-JUN-11 11.28.45.764386 PM -05:00";
        //comment = comment.replaceAll("\\)", "\\\\)");
        //comment = comment.replaceAll("\\(", "\\\\(");
          if(comment == null || comment.length() < 100)
          {
            System.out.println();  
          }
         String[] strArray =    comment.split(" ");
         for (int i = 0; i < strArray.length; i++) 
           { 
              if(strArray[i].length() > 100)
               {
                 int iter = strArray[i].length() / 100 ;
                 int count = 100 ;
                 int initCount = 0 ;
                 String strReplace = null;

                    for(int j =0 ; j< iter ; j++)
                    {
                      strReplace = strArray[i].substring(initCount ,count); 

                      String strToReplace =  strReplace + "\n" ;
                      comment = comment.replaceAll(strReplace,strToReplace);
                      //comment = comment.replaceAll("\\)", "\\\\)");
                      //comment = comment.replaceAll("\\(", "\\\\(");
                      //comment = comment.replaceAll("\\\\", "");
                      System.out.println(comment);
                      System.out.println(comment.contains("\n"));   
                      initCount = count; //+1 ; 
                      count = count +100 ;
                    } 

                }   

            }
    }

When I run I get the following exception:

Exception in thread “main” java.util.regex.PatternSyntaxException: Unmatched closing ‘)’
near index 4
HK$.3)Booking:virginiawong@fahkco.com.hk4)FCR&DOC:emilywu@fahkco.com.hkTel:00852-
23021977Fax:00852-2

From my understanding I have to escape the parantheses'(‘,’)’,
I tried to do this(look at the commented part in the code)there was nt any exception but the newline I am appending to the string doesn’t seem to appear.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:59:38+00:00Added an answer on June 8, 2026 at 2:59 pm

    String.replaceAll usess regular expressions for the first argument, and characters such as ) have special meaning when interpreted as regular expressions.

    Try String.replace instead. (It still replaces all occurrences of the given substring.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take a look at the following C# code: byte[] StringToBytesToBeHashed(string to_be_hashed) { byte[] to_be_hashed_byte_array
Please take a look at the following code: public static void main(String[] args) {
I have a string with url.Please take a look at the following code.I am
I'm developing a plugin. Take a look at the following code. string request(char post_params[])
Look at the following code: class A { public string DoSomething(string str) { return
Have a look at the following code: #include<unistd.h> #include<stdlib.h> #include<stdio.h> #include<string.h> #include<sys/types.h> main() {
Have a look at following code: @Local public interface MyService { void printMessage(); }
Pls look at following code <select name=VideoType id=VideoType style=width:60px> <option value=All>All</option> <option value=Movie>Movie</option> <option
Look at the following code: ECHO A2 MKDIR -v /tmp/My Batch Script File Assignment
Please look at the following code: char* test ( ) { char word[20]; printf

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.