JSFiddle - React, Tailwind, and code Playground

HTML

<a id="post_link">post</a>

JavaScript

var url = "http://google.com/stackoverflow/post/1";

var matches = url.match(/^http\:\/\/([\w\.]+)\/(\w+)\/.+/);

if( matches ){
    var newURL = "http://" + matches[1] + "/" + matches[2] + "/";
    alert( newURL );
}

document.getElementById('post_link').href = newURL;