日期:2014-05-16 浏览次数:20341 次
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
</head>
<body>
<script>
var url=/(\w+):\/\/([\w.]+)\/(\S*)/;
var text="visit my blog at http://www.example.com/david";
var result=text.match(url);
if(result!=null){
var fullurl=result[0];
var protocol=result[1];
var host=result[2];
var path=result[3];
alert(fullurl\nprotocol\nhost\npath);
}
</script>
</body>
</html>