首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

急救:关于一个正则表达式的应用,该如何解决

2012-03-02 
急救:关于一个正则表达式的应用一个字符串,形式如下:palign center ahref http://www.where.com/inde

急救:关于一个正则表达式的应用
一个字符串,形式如下:

<p   align= 'center '> <a   href= 'http://www.where.com/index.php '> aaa </a> </p> <p   align= 'center '> <a   href= 'http://www.where.com/index.php '> aaa </a> </p> <p   align= 'center '> <a   href= 'http://www.where.com/index.php '> aaa </a> </p> <p   align= 'center '> <a   href= 'http://www.where.com/index.php '> aaa </a> </p> <p   align= 'center '> <a   href= 'http://www.where.com/index.php '> aaa </a> </p>

怎么能得到这样的形式呢:

<p   align= 'center '> </p> <p   align= 'center '> </p> <p   align= 'center '> </p> <p   align= 'center '> </p> <p   align= 'center '> </p>

就是把所有的 <a   href= 'http://www.where.com/index.php '> aaa </a> 都去掉?

我用replace()方法,但正则写的不对。

[解决办法]
正则 / <a.*? <\/a> /g
[解决办法]
<textarea name=textarea1>
<p align= 'center '> <a href= 'http://www.where.com/index.php '> aaa </a> </p> <p align= 'center '> <a href= 'http://www.where.com/index.php '> aaa </a> </p> <p align= 'center '> <a href= 'http://www.where.com/index.php '> aaa </a> </p> <p align= 'center '> <a href= 'http://www.where.com/index.php '> aaa </a> </p> <p align= 'center '> <a href= 'http://www.where.com/index.php '> aaa </a> </p>

</textarea>

<script>
var str=textarea1.value;
re=/ <a.*? <\/a> /g;
str=str.replace(re, " ");
alert( str);

</script>

热点排行
Bad Request.