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

急求正则解决解决方案

2012-04-15 
急求正则解决HTML codep classchart z今日:em8/emspan classpipe|/span昨日:em11/em

急求正则解决

HTML code
<p class="chart z">今日:<em>8</em><span class="pipe">|</span>昨日:<em>11</em><span class="pipe">|</span>帖子:<em>95</em><span class="pipe">|</span>会员:<em>41</em><span class="pipe">|</span>欢迎新会员:<em><a class="xi2" target="_blank" href="space-username-vling5.html">vling5</a></em></p>


我想从html里得到一个数组,里面是 8,11,95,41应该怎么写呢?急

[解决办法]
HTML code
<!DOCTYPE HTML><html>    <head>        <meta charset="gb2312" />        <title></title>            <style>            body {font-size:12px;}        </style>            </head>    <body>        <div id="t">            <p class="chart z">今日:<em>8</em><span class="pipe">|</span>昨日:<em>11</em><span class="pipe">|</span>帖子:<em>95</em><span class="pipe">|</span>会员:<em>41</em><span class="pipe">|</span>欢迎新会员:<em><a class="xi2" target="_blank" href="space-username-vling5.html">vling5</a></em></p>        </div>        <script>            function $(el){                return typeof el == 'string' ? document.getElementById(el) : el;            }            var s = $('t').innerHTML;            var re = /<em>(\d+)<\/em>/g;            var s = s.match(re).join(',').replace(/[^\d,]/g, '');            alert(s.split(','))        </script>    </body></html> 

热点排行