每次用到JS替换字符串都要想半天,给他写出来得了。。
<script language="javascript">
$(function(){
var str = 'rtsp://123.1.123.12:1234567/1d8a097f_51bf_4ef2_8380_71d63e9fb97a/c1v1.3gp';
var re = /\:\/\/.*$/i;
if(re.test(str)){
var newStr = str.substring(str.indexOf("://")+3, str.length);
var strarray = newStr.split("/");
alert(strarray[0].substring(0, strarray[0].indexOf(":")));
alert(replaceStr(strarray[1]));
}
function replaceStr(str){
var newstring = str;
while(newstring.indexOf("_") > 0)
{
newstring = newstring.replace("_","-");
}
return newstring;
}
});
</script>