Blog Archive for July 7, 2016

RegEx Search and Replace in Java

July 7, 2016

I wanted to remove the contents of any tags in my XML that ended with the word Password, and replace the password with stars. So:

<xml>
  <password>ABC123</password>
  <securityPassword>sekr1t</securityPassword>
  <username>FRED</username>
</xml>

should turn into

<xml>
  <password>**</password>
  <securityPassword>**</securityPassword>
  <username>FRED</username>
</xml> …