JSFiddle - React, Tailwind, and code Playground
by klierik
HTML
<input id="input" type="text" value="https://htmlforum.io/topic/63758-zamena-teksta-na-html-css-js/">
<br>
<button id="button">Update URL</button>
<br>
<div id="result"> </div>
CSS
input {
width: 90%;
padding: 20px 15px;
}
#button {
margin: 30px 0;
}
#result {
padding: 10px;
background: #f1f1f1;
}
JavaScript 1.7
document.getElementById("button").addEventListener("click", function() {
let input = document.getElementById('input');
let result = document.getElementById('result');
let url = input.value;
let index = url.search(/[\/\/]\w*.(\/)/);
const newDomain = 'newdomain.org'
const newUrl = url.replace(/(http(s)?:\/\/).+?(\/.+)$/, `$1${newDomain}$3`)
result.innerText = newUrl;
});