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

  • Home
  • SEARCH
  • 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 5973947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:52:21+00:00 2026-05-22T20:52:21+00:00

I am trying to replace some words from a string and use following code

  • 0

I am trying to replace some words from a string and use following code

someMoreString = someString.replaceAll("\\b(shoe||apple|search|employee|expert)\\b", "");

It works fine. Today I found that it does not replace some words. The replace list is long
I cannot verify all. However, I found search word was never replaced in files. I doubt that there could be more cases like this.

Any idea why is it happening? How can I stop this?

Edit

Thank you all for your answers. I found the solution 🙂

I was adding two bar signs in replace string, that cause for this problem.
For example:

someMoreString = someString.replaceAll(“\b(shoe||apple|search|employee|expert)\b”, “”);

I do not know, why it did not give error and why it replaced some words.

  • 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-22T20:52:22+00:00Added an answer on May 22, 2026 at 8:52 pm

    Answer after updated question

    The issue with your double pipe was that it will look for matches to replace, and hence replace any single occurrence of something matching the first word (“shoe”), and if it doesn’t work look for the next potential match, which is an empty string (between the 2 pipes). So you’d find these matches and replace them (ironically) with empty strings as well. As a match was found for this position, it switches to the next potential positions and doesn’t check the other words for that one.

    Quite likely, any word after the doubled-pipe was never replaced.

    It didn’t yield an error because the syntax is valid and there are legitimate cases where you’d want to look for empty strings to insert characters.


    Original answer

    Kept for similar errors encountered by others.

    This obviously works, so there are only a few options left:

    1. You need to assign the return value (string are immutable in Java, as also mentioned by Ehran)
    2. There are some non-printable characters in the string;
    3. There is an encoding issue when you read the input and compare;
    4. You word is delimited by something that doesn’t register a boundary.
    5. You want a case-insensitive search (use Pattern.compile(regex, flags).matcher(str).replaceAll(repl) instead, with a CASE_INSENTIVE flag to compile the pattern)
    6. There’s something wrong somewhere else that we cannot see because you give:
      • neither the whole code
      • nor the input data.

    Please provide more code and your input excerpt.

    If you read from a socket, do make sure as well that you specify the right headers for your request and that you use valid content type and character encoding. Please make also sure that you are not using a strange encoding on your source files and your input data files.

    This is partially re-written off of another answer I gave on this question about why the java String.contains method does not return found matches correctly.

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

Sidebar

Related Questions

I currently use Com4j to talk to iTunes from my Java app, unfortunately it
I am trying the fizzbuzz program from here: Why Can't Programmers.. Program? Write a
I would like to be able launch a 2nd Preference screen from my PreferenceActivity.
I am trying to create a postage label that is populated dynamically in C#.
can someone explain what is wrong with this delete command, i am trying to
I am trying to get stock prices by scraping google finance pages, I am
I'm trying to add a content_save_pre filter to update a custom field based on
I have a data Store that gets it's information from a JSON api on
I've got a class that stores an image along with it's filename. I've created
The PHP function eval() appears to be a rather interesting function. Can someone explain

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.