<script>
var str="http://community.csdn.net/Expert/PostNew.asp?room=304"
var re=/(?:http\:\/\/)([^/]*)/g;
re.test(str)
alert(RegExp.$1);
</script>
var str="http://community.csdn.net/Expert/PostNew.asp?room=304"
var re=/(?:http\:\/\/)([^/]*)/g;
re.test(str)
alert(RegExp.$1);
</script>
正则如下:^(http\:\/\/)?([^/]*).*$对于
http://community.csdn.net/Expert/topic/5660/5660942.xml?temp=.5925257
还是
community.csdn.net/Expert/topic/5660/5660942.xml?temp=.5925257
这两种情况均能匹配取出<script language="javascript">
var str="http://community.csdn.net/Expert/PostNew.asp?room=304"
var test=/^(http\:\/\/)?([^/]*).*$/g;
test.test(str)
alert(RegExp.$2);
</script>