请教个正则表达式.如何把<a href="ftp://ftp.sohu.com">ftp://ftp.sohu.com</a>...
把 <a href= "ftp://ftp.sohu.com "> ftp://ftp.sohu.com </a>
替换成ftp://ftp.sohu.com.
同时 <a href= "http://www.sohu.com "> http://www.sohu.com </a>
能保持原样.
谢谢!
------解决方案--------------------没说清楚,是ftp的就换?http就不换?
还是这样的
var a= ' <a href= "ftp://ftp.sohu.com "> ftp://ftp.sohu.com </a> <a href= "http://www.sohu.com "> http://www.sohu.com </a> '
alert(a.replace(/ <a href= "ftp:\/\/ftp.sohu.com "> ftp:\/\/ftp.sohu.com <\/a> /g, "ftp://ftp.sohu.com "))
------解决方案-------------------- <script type= "text/javascript ">
alert(
' <a href= "ftp://ftp.sohu.com "> ftp://ftp.sohu.com </a> '.replace(/ftp:\/\/ftp/g, "http:\/\/www ")
)
</script>
------解决方案-------------------- <script>
var str= ' <a href= "ftp://ftp.sohu.com "> ftp://ftp.sohu.com </a> <a href= "http://www.sohu.com "> http://www.sohu.com </a> '
var re=/ <a href=\ "ftp[^\ "]+\ "> (.*?) <\/a> /g;
alert(str.replace(re, "$1 "))
</script>
------解决方案-------------------- <html>
<head>
<meta http-equiv= "content-type " content= "text/html; charset=UTF-8 "/>
<link rel= "stylesheet " href= ".css "/>
<title> New Document </title>
<style type= "text/css ">
<!--
-->
</style>
<body>
<textarea id= "ta "> 把 <a href= "ftp://ftp.sohu.com "> ftp://ftp.sohu.com </a>
替换成ftp://ftp.sohu.com.
同时 <a href= "http://www.sohu.com "> http://www.sohu.com </a>
能保持原样. </textarea>
<script type= "text/javascript ">
<!--
var reg = / <a\s+[^> ]*href= "(ftp:[^ "]+) "[^> ]*> [\s]*\1[\s]* <\/a> /g;
var ta = document.getElementById( "ta ");
ta.value = ta.value.replace(reg, "$1 ");
//-->
</script>
</body>
</html>
------解决方案-------------------- <a[^> ]*> (? <ftpname> [^ <]*) <[^> ]*>
然后组ftpname取代就可以了
//////////////////////////////////////////////
MSN:bdbox@hotmail.com请给我一个与您交流的机会!