I have this link: "sound:https://cdn.jsdelivr.net/gh/ArSrNa/CDN/audio/%E6%B5%85%E5%A0%B4%E4%BD%B3%E8%8B%97%20-%20love%20the%20way.mp3?"
I would like to remove this from the beginning of the link: "sound:", and this from the end "?" so that I can play the audio on the link.
this is what i have so far. Every help is welcome.
<audio id="myAudio">
<source src="sound:https://cdn.jsdelivr.net/gh/ArSrNa/CDN/audio/%E6%B5%85%E5%A0%B4%E4%BD%B3%E8%8B%97%20-%20love%20the%20way.mp3?" type="audio/mpeg">
</audio>
<button onclick="playAudio()" type="button">Play Audio</button>
<button onclick="pauseAudio()" type="button">Pause Audio</button>
<script>
var x = document.getElementById("myAudio");
s = x.replace('[sound:','').replace(']','');
function playAudio() {
s.play();
}
function pauseAudio() {
s.pause();
}
</script>
<source src="https://cdn.jsdelivr.net/gh/ArSrNa/CDN/audio/%E6%B5%85%E5%A0%B4%E4%BD%B3%E8%8B%97%20-%20love%20the%20way.mp3" type="audio/mpeg">
This would achieve exactly what you wanted. Why need a script?
There will almost certainly be a more robust regex based answer to this but the simplest way in my eyes, if you can rely on the end of the string always ending in .mp3 is to do string replacement. So it seems you pretty much have it with a couple of minor mistakes.
This s = x.replace('[sound:','').replace(']',''); should be s = x.replace('sound:','').replace('.mp3?','.mp3');
Adding .mp3 to the replacement will ensure no other question marks are removed out of context
I'm guessing this is what you are trying to do:
myURLstring.split(/sound\:|\?|\]/)[1]
var string1 = 'sound:https://cdn.jsdelivr.net/gh/ArSrNa/CDN/audio/%E6%B5%85%E5%A0%B4%E4%BD%B3%E8%8B%97%20-%20love%20the%20way.mp3?'
var string2 = '[sound:https://cdn.jsdelivr.net/gh/ArSrNa/CDN/audio/%E6%B5%85%E5%A0%B4%E4%BD%B3%E8%8B%97%20-%20love%20the%20way.mp3]'
console.log(string1.split(/sound\:|\?|\]/)[1]);
console.log(string2.split(/sound\:|\?|\]/)[1]);