I have a tag like following, I want to replace the USERNAME in this, here user name is dynamic value:

<ns3:AgentName xmlns:ns3="http://example.com">USERNAME</ns3:AgentName>

I want to replace this tag with

<ns3:AgentName>XXXXXXX</ns3:AgentName>

I tried the regex like following:

<ns3:AgentName.*</ns3:AgentName>
<ns3:AgentName xmlns:ns3="http://example.com">.*</ns3:AgentName>

Nothing worked for me

1 Answers

0
TroyK On

This worked for me when I tested it at RegexPlanet.

My regular expression was:

(\<ns3:AgentName) xmlns:ns3="http://example.com"(\>).*(\</ns3:AgentName\>)

If you want to replace USERNAME with x's, my replacement was:

$1$2xxxxxx$3

If you want to put USERNAME in the replacement, I'd make my regular expression this:

(\<ns3:AgentName) xmlns:ns3="http://example.com"(\>.*)(\</ns3:AgentName\>)

and my replacement this:

$1$2$3