需要 java Regex 从特定字符串中删除/替换 XML 元素

sam*_*ash 5 java regex

我在获取正确的正则表达式时遇到问题。我有以下 xml 作为字符串

<user_input>
<UserInput Question="test Q?" Answer=<value>0</value><sam@testmail.com>"
</user_input>
Run Code Online (Sandbox Code Playgroud)

现在我只需要从 Answer 属性中删除 xml 字符。所以我需要以下内容:-

<user_input>
<UserInput Question="test Q?" Answer=value0value sam@testmail.com"
</user_input>
Run Code Online (Sandbox Code Playgroud)

我试过下面的正则表达式,但没有解决:-

str1.replaceAll("Answer=.*?<([^<]*)>", "$1");
Run Code Online (Sandbox Code Playgroud)

它删除了之前的所有文本..

有人可以帮忙吗?

Kas*_*mvd 0

您需要将其放入?第一组中以使其不贪婪,也不需要Answer=.*?

str1.replaceAll("<([^<]*?)>", "$1")
Run Code Online (Sandbox Code Playgroud)

演示版