【问题标题】:Match SteamID with ban duration from listid result将 SteamID 与 listid 结果中的禁令持续时间相匹配
【发布时间】:2015-08-01 19:14:16
【问题描述】:

我使用 php 库通过 rcon 在 srcds-server 上执行命令。在这种情况下,我想获得所有禁令及其持续时间。当我通过 rcon 执行listid 时,经过一些解析,我得到了例如以下文本:

1 STEAM_1:0:12345678 : permanent 2 STEAM_1:0:87654321 : 30.000 min

现在我想得到一个包含 SteamID 和每组持续时间的数组,如下所示:

$Bans = [
   "STEAM_1:0:12345678" => "permanent",
   "STEAM_1:0:87654321" => "30.000 min",
]

由于我不能以一种很好的方式使用explode 来为我做这件事(或者至少我不知道我应该怎么做),我想用正则表达式来试试。到目前为止我的尝试:

/^(?:\d\s)(STEAM_[0-5]:[01]:[0-9]{1,8})(?:\s:\s)(permanent|\d{1,}\.000\smin)/g

但这并没有以正确的方式匹配它。你会怎么做?

【问题讨论】:

    标签: php regex parsing steam


    【解决方案1】:

    preg_match_all 的正确正则表达式是:

    preg_match_all("/(?:\d\s)(STEAM_[0-5]:[01]:[0-9]{1,8})(?:\s:\s)(permanent|\d{1,}\.000\smin)/", $input_lines, $output_array);
    

    我需要删除^。现在,我什至不必事先做所有的爆炸。我什至从原始结果中匹配正确的部分:

    ID filter list: 2 entries 1 STEAM_1:0:12345678 : permanent 2 STEAM_1:0:87654321 : 30.000 min L 05/20/2015 - 15:48:53: rcon from "188.40.142.20:60799": command "listid"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-31
      • 2018-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-19
      • 1970-01-01
      相关资源
      最近更新 更多