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

根据正则表达式找出符合的字符串解决方法

2012-05-20 
根据正则表达式找出符合的字符串随便写个正则 然后 找出和正则符合的字符串如http://paper.wenweipo.com/\

根据正则表达式找出符合的字符串
随便写个正则 然后 找出和正则符合的字符串 
 如 http://paper.wenweipo.com/\d+/\d+/\d+/CH\d+.htm 就会找到
<li><a href="http://paper.wenweipo.com/2012/05/16/CH1205160004.htm" target="_blank">顶顶顶顶</a></li> 
  这个用js要怎么弄。 求大侠帮忙。。。。。。。。。。。。。。先谢谢了 。。 或者给我个 实现的思路 。。。。

[解决办法]

HTML code
<!DOCTYPE HTML><html>    <head>        <meta charset="gb2312" />        <title></title>    </head>    <body>        待测文本<div id="str"><li><a href="http://paper.wenweipo.com/2012/05/16/CH1205160004.htm" target="_blank">顶顶顶顶</a></li></div>        输入正则<textarea id="test"></textarea>        <button id="btn">点击</button>        <script>            function $(el){                return typeof el == 'string' ? document.getElementById(el) : el;            }            $('btn').onclick = function(){                var re = $('test').value;                var s = $('str').innerHTML                var r = new RegExp(re, 'i')                alert( s.match(r) )                        }        </script>    </body></html> 

热点排行
Bad Request.