I have modified the code for demo and below code is working as expected:
(for verification I have put alert for url, you can remove that)
<div id="mm">Some Crap Text[img]https:
</div>
<script>
var s;
s = document.getElementById("mm").innerHTML
var afterImg = s.split("[img]")[1];
var url = afterImg.split("[/img]")[0];
alert(url);
var b = "<img src=" + url + "></img>"
document.getElementById("mm").innerHTML = b;
</script>
Please let me know if any further issue. Thanks.