0

这是我的 RE,我将它与preg_match_allPHP 一起使用,但我得到的结果不准确 http://screencast.com/t/FPsoJkAT

#(\d+/\d+/\d+)|(\d+:\d+(AM|PM).*?[$]\d)#i

我得到了应该被跳过的额外行(空行 + PM 和 AM)

当我尝试使用 RE 实用程序对其进行测试时,这是预期的结果。 http://screencast.com/t/RRteFlCD

有人请帮助我对这个 RE 进行排序,以将确切的结果与该实用程序产生的正确顺序相匹配。

RE 不能正常工作

 preg_match_all("#(\d+/\d+/\d+)|(\d+:\d+(AM|PM).*?[$]\d)#i",$response,$result);

输入

13年11月1日$ 4.34下午10点02 Internet79kbs $ 0.02下午6点42 Internet34kbs $ 0.01 5时37 PM0438377989Optus SMS1 $ 0.000下午5点21 Internet253kbs $ 0.06 3点59 PM0438377989Optus SMS1 $ 0.000 3点59 PM0438377989Optus SMS1 $ 0.000 3点59 PM0438377989Optus SMS1 $ 0.000 3点57 PM0438377989Optus SMS1 $ 0.000 12:40 PM Internet462kbs $ 0.10 12:34 Internet1659kbs $ 0.37上午11:26 Internet54kbs $ 0.01 11:20 AM0411000321DIV-VoiceMail00:00:19 $ 0.00包装11:20 AM Internet76kbs $ 0.02 11:19 AM0438377989Optus SMS1 $ 0.000 11:19 AM0438377989Optus SMS1 $ 0.000 10:02 AM0414828271Optus SMS1 $ 0.000上午09时32 Internet297kbs $ 0.07 08:46 AM0282700517Sydney00: 03:15 $3.59 08:40AM0411000321DIV-VoiceMail00:00:25 $0.00 08:39AM Internet388kbs $0.09 第 1 页,共 3 页 打印使用详情 16/01/2013 https://www.optus.com.au/portal/site/customercentre/template.BINARYPORTLET/m ... ( 由于处理时间,最近拨打的电话或最近的数据使用可能不会出现在上述使用交易详情页面中。某些类型的包含值或折扣也可能不会显示。如果如果您更改费率计划或在您的账单周期中途生效的附加项目,您的使用摘要将不准确,直到您的下一个账单周期开始。显示的金额是:GST 仅适用于电话、后付费移动和MOB ILE宽带服务。GST包括预付费移动服务。10/01/13 $ 22.94 10:00 PM Internet239kbs $ 0.05 10:00 $ 0.05optus sms1 $ 0.0 08:56 $ 0.000 08:51 $ 0.05optus sms1 $ 0.000 08:51 PM0417973105optus sms1 $ 0.000 08: 45PM0417973105Optus SMS1 0.000 美元 06:15PM Internet23kbs 0.01 美元 06:00PM Internet156kbs 0 美元。03 06:00 PM0738483389Brisbane00:15:18 $ 13.41 04:22 PM0438377989Optus SMS1 $ 0.000 04:22 PM0438377989Optus SMS1 $ 0.000下午2点20 Apps使用Mobile152kbs $ 0.03下午2点14分Internet154kbs $ 0.03 02:14 PM0282700517Sydney00:05:49 $ 5.23 02:03 PM0411000321DIV-VoiceMail00:00:24 $ 0.00包装01 :55PM Internet958kbs $ 0.21 01:54 PM0282700517Sydney00:01:04 $ 1.95 01:53 PM0411000321VoiceMail00:00:32 $ 0.82 12:50 PM0411000321DIV-VoiceMail00:00:03 $ 0.00包装12:18 PM0295521298Sydney00:00:07 $ 1.14 10:04 AM0411000321DIV-VoiceMail00:00:26 $ 0.00包装08: 07AM Internet76kbs $0.02 第 2 页,共 3 页 打印使用详情 16/01/201321 01:54 PM0282700517S $ 1.95 01:53 PM0411000321VOVOIVEMAIL00:00:32 $ 0.82 $ 0.82 $ 0.82 $ 0.82 $ 0.82 $ 0.82 $ 0.82:03 $ 0.03 $ 0.03 $ 0.03 $ 0.03 $ 0.03 $ 0.03 $ 0.11月12:18 $ 1.14 $ 1.14 10:04 am0411000321div-voicemail00:00:00:00:00:00:00:00:00:00:00:00:00:00:00 $ 0.08:07 AM Internet76KBS $ 0.08:07第 2 页,共 3 页 打印使用详情 16/01/201321 01:54 PM0282700517S $ 1.95 01:53 PM0411000321VOVOIVEMAIL00:00:32 $ 0.82 $ 0.82 $ 0.82 $ 0.82 $ 0.82 $ 0.82 $ 0.82:03 $ 0.03 $ 0.03 $ 0.03 $ 0.03 $ 0.03 $ 0.03 $ 0.11月12:18 $ 1.14 $ 1.14 10:04 am0411000321div-voicemail00:00:00:00:00:00:00:00:00:00:00:00:00:00:00 $ 0.08:07 AM Internet76KBS $ 0.08:07第 2 页,共 3 页 打印使用详情 16/01/2013https://www.optus.com.au/portal/site/customercentre /template.BINARYPORTLET/m ... 使用余额可能不考虑上限包含/折扣或调整。对于后付费,如果您有超过 7000 条记录,则显示的未计费使用量将是近似值。有关实际费用,请参阅您的发票。第 3 页,共 3 页 打印使用详情16/01/2013 https://www.optus.com.au/portal/site/customercentre /template.BINARYPORTLET/m ...

谢谢

4

1 回答 1

1

preg_match_all()的结果数组是一个二维数组。$result[0]是整个 RE 的所有匹配项的数组。其余的是每个匹配中第 th 个捕获组$result[i]的数组。i

因此,出于您的目的,您所关心的只是$result[0]. 我对此进行了测试,它有 47 个元素。

此外,您可能应该将 RE 中的所有组更改为非捕获组,以避免首先生成所有这些无关字符串。所以每一个都(...)应该是(?:...)

print_r($result[0])印刷:

Array
(
    [0] => 11/01/13
    [1] => 10:02PM Internet79kbs $0
    [2] => 06:42PM Internet34kbs $0
    [3] => 05:37PM0438377989Optus SMS1 $0
    [4] => 05:21PM Internet253kbs $0
    [5] => 03:59PM0438377989Optus SMS1 $0
    [6] => 03:59PM0438377989Optus SMS1 $0
    [7] => 03:59PM0438377989Optus SMS1 $0
    [8] => 03:57PM0438377989Optus SMS1 $0
    [9] => 12:40PM Internet462kbs $0
    [10] => 12:34PM Internet1659kbs $0
    [11] => 11:26AM Internet54kbs $0
    [12] => 11:20AM0411000321DIV-VoiceMail00:00:19 $0
    [13] => 11:20AM Internet76kbs $0
    [14] => 11:19AM0438377989Optus SMS1 $0
    [15] => 11:19AM0438377989Optus SMS1 $0
    [16] => 10:02AM0414828271Optus SMS1 $0
    [17] => 09:32AM Internet297kbs $0
    [18] => 08:46AM0282700517Sydney00:03:15 $3
    [19] => 08:40AM0411000321DIV-VoiceMail00:00:25 $0
    [20] => 08:39AM Internet388kbs $0
    [21] => 16/01/2013
    [22] => 10/01/13
    [23] => 10:00PM Internet239kbs $0
    [24] => 10:00PM Internet46kbs $0
    [25] => 08:56PM0417973105Optus SMS1 $0
    [26] => 08:56PM0417973105Optus SMS1 $0
    [27] => 08:51PM0417973105Optus SMS1 $0
    [28] => 08:51PM0417973105Optus SMS1 $0
    [29] => 08:45PM0417973105Optus SMS1 $0
    [30] => 06:15PM Internet23kbs $0
    [31] => 06:00PM Internet156kbs $0
    [32] => 06:00PM0738483389Brisbane00:15:18 $1
    [33] => 04:22PM0438377989Optus SMS1 $0
    [34] => 04:22PM0438377989Optus SMS1 $0
    [35] => 02:20PM Apps Usage Mobile152kbs $0
    [36] => 02:14PM Internet154kbs $0
    [37] => 02:14PM0282700517Sydney00:05:49 $5
    [38] => 02:03PM0411000321DIV-VoiceMail00:00:24 $0
    [39] => 01:55PM Internet958kbs $0
    [40] => 01:54PM0282700517Sydney00:01:04 $1
    [41] => 01:53PM0411000321VoiceMail00:00:32 $0
    [42] => 12:50PM0411000321DIV-VoiceMail00:00:03 $0
    [43] => 12:18PM0295521298Sydney00:00:07 $1
    [44] => 10:04AM0411000321DIV-VoiceMail00:00:26 $0
    [45] => 08:07AM Internet76kbs $0
    [46] => 16/01/2013
    [47] => 16/01/2013
)
于 2013-02-07T00:45:58.870 回答