I have to replace the content of this xml string through java
<My:tag>value_1 22
value_2 54
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 
 symbol
but if I try to replace the string without the 
 symbol, everything goes fine.
Suggestions? Thanks
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
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:
Replacement:
Test string: