 <pre><code>text = (text.replaceAll( "(?i)(&lt;a[^&gt;]*?\\stestexpression\\s*)=\"", "" )); return text.replaceAll("}\"\\shref.+&lt;/a&gt;", "}"); </code></pre> <p>But still looking for 1 line solution .</p>