Try this:
var input="https://192.168.1.243/admin/build/take_control";
var output = input.match(/https?:\/\/[^\/]+/)[0]
console.log(output);
it will work if you have http or https at the beginning.
solved Get data after the third forward slash in a string