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


I tried the regex like following:

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

Nothing worked for me

1 Answers

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:


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: