function aaa()
{
//测试使用
var s1 = "f http://ubooo.com/test/123.html"
var s2 = " http://ubooo.com/test/123_2.html"
var reg = /\/([\d]+)(\.|[\d_]+\.)html/
var arr = s1.match(reg)
if (arr != null)
{
var url = " http://ubooo.com/Article.php?id=" + arr[1]
alert(url)
}//正常使用用以下代码
/*
var localUrl = location.href//获取当前URL地址
var reg = /\/([\d]+)(\.|[\d_]+\.)html/
var arr = localUrl.match(reg)
if (arr != null)
{
alert(1)
var url = " http://ubooo.com/Article.php?id=" + arr[1]
location.href = url//跳转
}
*/
}
</script>
<input type="button" value="测试" onclick="aaa()"/>
var url = "http://v.youku.com/v_show/id_XMjg5OTY1NzMy.html"var str = url.split("/").pop().replace(/(^id_)|(\.\S+$)/g,"")
// 输出结果为 XMjg5OTY1NzMy
console.log(str)
字符串提取代码奉上