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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:08:03+00:00 2026-05-11T04:08:03+00:00

I have to replace the content of this xml string through java <My:tag>value_1 22&#xA;value_2

  • 0

I have to replace the content of this xml string through java

<My:tag>value_1 22&#xA;value_2 54&#xA;value_3 11</My:tag> 

so, this string has been taken from an xml and when I acquire it I have this result:

<My:tag>value_1 22 value_2 54 value_3 11</My:tag> 

If I try to replace the content by this way:

String regex =  '(<My:tag>)(.*)(</My:tag>)'; String new_string = old_string.replaceAll(regex,'<My:tag> new_stuff </My:tag>'); 

I get no result. I think because of the &#xA; symbol

but if I try to replace the string without the &#xA; symbol, everything goes fine.

Suggestions? Thanks

  • 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. 2026-05-11T04:08:03+00:00Added an answer on May 11, 2026 at 4:08 am

    I’m not 100% sure how the java regex-engine works, but I can’t possibly imagine that an entity would cause your problems. You should first try to simply remove your brackets, since you’re replacing the entire expression, and not extracting anything.

    What might be causing it though is if your entity is actually translated to a new-line, it might be the case that your regex won’t catch it unless you’re explicitly doing a multiline match. You could also try doing

    [.\n]* 

    instead of your

    .* 

    This might be a bid greedy though, and the backtracking to much for the matcher to handle. Unfortunately, I don’t have any java stuff installed on this machine, so I can’t really try it and test it. One other possibility would be to actively look for the next opening angle bracket, like so:

    [^<]*  

    EDIT:
    As you suggested, i tried your link and the following worked perfectly:

    Expression:

    <My:tag>[^<]*</My:tag> 

    Replacement:

    <My:tag> new_stuff </My:tag> 

    Test string:

    <My:tag>value_1 22&#xA;value_2 54&#xA;value_3 11</My:tag> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this java string: String bla = <my:string>invalid_content</my:string>; How can I replace the
I have a pipe delimited string like this: blah|blah|blah|blah|blah|blah|blah|blah|blah|oldDate|blah|blah| I would like replace the
I have this code, and I'm trying to add a fadeIn once the content.replace
I have some content from server using $.ajax() function. I try to replace some
This is what I currently have: CREATE OR REPLACE TRIGGER MYTRIGGER AFTER INSERT ON
I have following string String str = replace :) :) with some other string;
I have hit a classic problem of needing to do a string replace on
If you have to use String.Replace() to replace test 50 times, you essentially have
I have a bit of code that looks like this: text = reg.Replace(text, new
I have a little script that replace some text, that come from a xml

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.