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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:30:50+00:00 2026-05-14T20:30:50+00:00

I need to do a simple string replace operation on a segment of string.

  • 0

I need to do a simple string replace operation on a segment of string. I ran into the following issue and hope to get some advice.

  1. In the original string I got, I can replace the string such as <div class="more"> to something else.
  2. BUT, in the same original string, if I want to replace a much long string such as the following, it won’t work. Nothing gets replaced after the call.

<div class="more"><a href="http://SERVER_name/profiles/atom/mv/theboard/entries/related.do?email=xyz.com&amp;ps=20&amp;since=1273518953218&amp;sinceEntryId=abc-def-123-456">More...</a></div>

I tried these two methods:

originalString.replaceFirst(moreTag, newContent);
originalString.replaceAll(moreTag, newContent);

Thanks in advance.

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

    You need to get hold of the result of the replacement and use it further:

    String newString = originalString.replaceFirst(moreTag, newContent);
    System.out.println(newString);
    

    Explanation: strings in Java are immutable. The behavioral methods of java.lang.String won’t change the internal value. They instead will return the modified result.

    If that still doesn’t return the desired result, then the moreTag simply didn’t match anything. The methods you mentioned expects a regular expression. You can find in the Pattern javadoc how to compose a valid regex pattern.

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

Sidebar

Related Questions

I need to replace a simple string in a minified .js file after a
I need to convert a string vector in a simple string. I do not
I need an simple way to check whether a string that is sent to
I have a string input from which I need to extract simple information, here
I have a simple Dictionary(of String, Object) that I need to iterate through and
I need to split a string without removing the separators. Is there a simple
Given a string of words separated by whitespace. Need to replace whitespaces with comma
I have a string I need to parse. The problem is that some parts
How can I replace String in xml .. I've <schema>src/main/castor/document.xsd</schema> I need to replace
I've created simple string class with some extra functions - its mainly for learning

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.