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

急求正则解决
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>