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 3805940
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:45:27+00:00 2026-05-19T14:45:27+00:00

I am struggling with string replacement that contains special regex characters. I got a

  • 0

I am struggling with string replacement that contains special regex characters. I got a list of separators from a file, and I need to replace the escaped form of these characters into the unescaped characters.

The mapping table is the following. Note that the escape character is known after parsing the file so I can’t hard code the replacement strings.

escapeChar + F + escapeChar <=> sep1
escapeChar + S + escapeChar <=> sep2
escapeChar + T + escapeChar <=> sep3
escapeChar + R + escapeChar <=> sep4
escapeChar + E + escapeChar <=> escapeChar

Let’s say that after parsing the file you have to the following separators

sep1 = | 
sep2 = ^
sep3 = &
sep4 = $
sep5 = \

So when you parse the file and the input is the following \F\\S\\T\\R\\E\. It should be translated into |^&$\

The following code is not working (I just tried with the first separator):

String sep1 = "|";
String escapeChar = "\\";
String x = "\\F\\\\S\\\\T\\\\R\\\\E\\";
x.replaceAll(Pattern.quote(escapeChar) + "F"
        + Pattern.quote(escapeChar), sep1);
System.out.println(x);
  • 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-05-19T14:45:28+00:00Added an answer on May 19, 2026 at 2:45 pm

    Strings are immutable in Java. String.replaceAll returns a new string with the replacements performed, rather than changing the contents of the existing string. Try:

    x = x.replaceAll(...);
    

    That seems to work fine, assuming I understood what you were trying to do.

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

Sidebar

Related Questions

Hi I'm struggling with some regex I've got a string like this: a:b||c:{d:e||f:g}||h:i basically
I am struggling with the following issue: I have an XML string that contains
Stuggling a little bit with the RegEx, I've got 4 codes in a string
Hello struggling here guys.. Is it possible to string replace anything between the the
string webPath = folderPath.Replace(\, /); Hi, I'm trying to replace the above but struggling.
Struggling a bit today. I have the following method that returns a list of
I am struggling with the code from few days can anyone help std::string str=uri_req1.substr(found+1);
I've been struggling with writing a single string into a file. I'm using just
I'm struggling to read query variables that contain more than 512 characters in the
I'm struggling to separate the dependencies in the following code: public static SiteConnector ConnectToSite(String

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.