日期:2014-05-16  浏览次数:20312 次

在线等 这个关于正则的脚本错在哪

<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>

将文件载入浏览器,为什么没有输出?是哪里出了问题?
正则表达式

------解决方案--------------------
js有这种写法么 :alert(fullurl\nprotocol\nhost\npath);
改成:alert(fullurl+"\n"+protocol+"\n"+host+"\n"+path);