 <p>You can make regular expression groups by using <code>(</code> and <code>)</code> and reference then in replace using <code>$N</code>, which will access <code>N-th</code> group.</p> <p>So in your case, you can do this regex: <code>([^: ]+:[^:]+:([^:]+):[^:]+:[^:]+)(:[^: ]+)</code> replace: <code>\1&lt;\2&gt;\3</code> or on some implementation <code>$1&lt;$2&gt;$3</code></p> <p>You can try it yourself here: <a href="https://www.regex101.com/r/hY8pY9/1" rel="nofollow">https://www.regex101.com/r/hY8pY9/1</a></p>