PHP正则表达式,只返回部分结果

时间:2013-02-19 20:21:00

标签: php regex

我有以下PHP正则表达式:

@<tr[\s\S]*?<a class="b1"[\s\S]*?<em[^>]*>([^<]*)[\s\S]*?stars_small_([0-9].[0-9])@

我在本网站上使用的内容:

Gamespy

我收回了这些数据:

[1] => Array
        (
            [0] => AC/DC Live: Rock Band Track Pack
            [1] => Ace Combat 6: Fires of Liberation
            [2] => All-Pro Football 2K8
            [3] => Alone in the Dark
            [4] => Armored Core 4
            [5] => Army of Two
            [6] => Army of Two: The 40th Day
        )

    [2] => Array
        (
            [0] => 3.5
            [1] => 2.5
            [2] => 3.5
            [3] => 3.5
            [4] => 2.5
            [5] => 3.5
            [6] => 3.5
        )

这就是我要找的东西,但是我似乎并没有收回所有的数据。我应该得到以下标题得分。但由于某种原因,我只得到其中一些。

AC/DC Live: Rock Band Track Pack     
Ace Combat 6: Fires of Liberation    
Afro Samurai         
Alan Wake    
Aliens vs. Predator  
All-Pro Football 2K8    
Alone in the Dark   
Amped 3     
Armored Core 4  
Army of Two 
Army of Two: The 40th Day   
Assassin's Creed     
Assassin's Creed II  
Assassin's Creed: Brotherhood    
Avatar: The Game

我在这里测试了我的正则表达式:

http://www.solmetra.com/scripts/regex/index.php

使用此HTML:

http://justpaste.it/20u5

任何帮助解释为什么我只回到一些结果将不胜感激。感谢

1 个答案:

答案 0 :(得分:1)

将子模式stars_small_([0-9].[0-9])更改为stars_small_([0-9](?:\.[0-9])?),因为某些网址只有SRC标记的IMG属性中的一位数。