SteamID match with ban duration from listid result

I am using php library to execute commands on srcds server via rcon. In this case, I want to get all the bans and their duration. When I execute listid

through rcon, I get, after some parsing, for example this text:

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

      

Now I want to get an array containing the SteamID and duration for each set, for example:

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

      

Since I can't use explode

to do this for me (or at least I don't know how to do it), I want to try it out with a regex. My attempt:

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

      

But this is not the correct path. How do you do it?

+3


source to share


1 answer


Correct regex with 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);

      



I needed to delete ^

. Now I don't even need to do all the blasts beforehand. I am comparing the correct parts even with the original result:

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"

      

0


source







All Articles