title: How to replace string values with "XXXXX" in java?
body: <p>I want to replace particular string values with "XXXX". The issue is the pattern is very dynamic and it won't have a fixed pattern in input data.</p>
  
  <p>My input data</p>
  
  <blockquote>
    <p><a href="https://internetbanking.abc.co.uk/personal/logon/login/?userId=Templ3108&amp;password=Got1&amp;reme" rel="nofollow noreferrer">https://internetbanking.abc.co.uk/personal/logon/login/?userId=Templ3108&amp;password=Got1&amp;reme</a></p>
  </blockquote>
  
  <p>I need to replace the values of userId and password with "XXXX". </p>
  
  <p>My output should be -</p>
  
  <blockquote>
    <p><a href="https://internetbanking.abc.co.uk/personal/logon/login/?userId=XXXX&amp;password=XXXX&amp;reme" rel="nofollow noreferrer">https://internetbanking.abc.co.uk/personal/logon/login/?userId=XXXX&amp;password=XXXX&amp;reme</a></p>
  </blockquote>
  
  <p>This is an one off example. There are other cases where only userId and password is present -</p>
  
  <blockquote>
    <p>userId=12345678&amp;password=stackoverflow&amp;rememberID=</p>
  </blockquote>
  
  <p>I am using Regex in java to achieve the above, but have not been successful yet. Appreciate any guidance.</p>
  
  <pre><code>[&amp;]([^\\/?&amp;;]{0,})(userId=|password=)=[^&amp;;]+|((?&lt;=\\/)|(?&lt;=\\?)|(?&lt;=;))([^\\/?&amp;;]{0,})(userId=|password=)=[^&amp;]+|(?&lt;=\\?)(userId=|password=)=[^&amp;]+|(userId=|password=)=[^&amp;]+
  </code></pre>
  
  <p>PS : I am not an expert in Regex. Also, please do let me know if there are any other alternatives to achieve this apart from Regex.</p>