I have a log file and trying to find instances of 2 consecutive lines.
Here is an extract of a file :
21:12:44 | Player "MinecraftNerd8" (DEAD) (id=630DB6BBFCCC2E66508D086E78D202BFA4FB1FB5 pos=<5215.0, 13515.6, 204.5>)[HP: 0] hit by Player "sbog 9000" (id=EAD177E916EE7D01F6DC47C59EAF4802A6061420 pos=<5211.9, 13516.6, 203.8>) into Torso(11) for 35 damage (Bullet_12GaugePellets) with BK-43 from 3.32238 meters
21:12:44 | Player "MinecraftNerd8" (DEAD) (id=630DB6BBFCCC2E66508D086E78D202BFA4FB1FB5 pos=<5215.0, 13515.6, 204.5>) killed by Player "sbog 9000" (id=EAD177E916EE7D01F6DC47C59EAF4802A6061420 pos=<5211.9, 13516.6, 203.8>) with BK-43 from 3.32238 meters
21:12:44 | Player "RMuckey06" (DEAD) (id=1BE787EF788074C94B0FB22785EAD502E58240C1 pos=<5214.1, 13515.8, 203.8>)[HP: 0] hit by Player "sbog 9000" (id=EAD177E916EE7D01F6DC47C59EAF4802A6061420 pos=<5211.9, 13516.6, 203.8>) into Head(0) for 8.75 damage (Bullet_12GaugePellets) with BK-43 from 2.24871 meters
21:12:44 | Player "RMuckey06" (DEAD) (id=1BE787EF788074C94B0FB22785EAD502E58240C1 pos=<5214.1, 13515.8, 203.8>) killed by Player "sbog 9000" (id=EAD177E916EE7D01F6DC47C59EAF4802A6061420 pos=<5211.9, 13516.6, 203.8>) with BK-43 from 2.24871 meters
21:12:51 | Player "Cogito8434" (id=26DE70CAEF00AE579AF8CA21ED3F1648DB316F1E pos=<4629.4, 15078, 476.3>) regained consciousness
I am trying to return data for these 2 lines :
21:12:44 | Player "MinecraftNerd8" (DEAD) (id=630DB6BBFCCC2E66508D086E78D202BFA4FB1FB5 pos=<5215.0, 13515.6, 204.5>)[HP: 0] hit by Player "sbog 9000" (id=EAD177E916EE7D01F6DC47C59EAF4802A6061420 pos=<5211.9, 13516.6, 203.8>) into Torso(11) for 35 damage (Bullet_12GaugePellets) with BK-43 from 3.32238 meters
21:12:44 | Player "MinecraftNerd8" (DEAD) (id=630DB6BBFCCC2E66508D086E78D202BFA4FB1FB5 pos=<5215.0, 13515.6, 204.5>) killed by Player "sbog 9000" (id=EAD177E916EE7D01F6DC47C59EAF4802A6061420 pos=<5211.9, 13516.6, 203.8>) with BK-43 from 3.32238 meters
The 1st line represents the final hit as indicated by the [HP: 0] and the 2nd line immediately after which contains killed by Player, confirms this was the final hit as further hits after payer is dead will still be logged.
Here is the preg_match_all code I am using
/(.*?)Player "(.*)" (DEAD) (id=(.*) pos=<(.*)>)[HP: 0] hit by Player "(.*)" (id=(.*) pos=<(.*)>) into (.*) for (.*) damage (.*) with (.*) from (.*) meters\s*
(.*?)Player "(.*)" (DEAD) (id=(.*) pos=<(.*)>) killed by Player (.*)/
I'm trying this in the onlinephp.io sandbox but no matter what I change it still wont return any data.
Appreciate any help
Edit : Ive tried the below and now get data matches However its essential only lines with [HP: 0] are returned
/(.*?) | Player "(.*)" (DEAD) (id=(.*) pos=<(.*)>) [HP:0] hit by Player "(.*)" (id=(.*) pos=<(.*)>) into (.*) for (.*) damage (.*) with (.*) from (.*) meters\s(.*?)Player "(.*)" (DEAD) (id=(.*) pos=<(.*)>) killed by Player (.*)/
Fixed : Thanks to everyone for their help. The correct regex was
/(.*?)Player "(.*)" \(DEAD\)\ \(id=(.*) pos=<(.*)>\)\[HP: 0\] hit by Player "(.*)" \(id=(.*)\ pos=<(.*)>\) into (.*)\((.*)\) for(.*)damage (.*) with (.*) from (.*)\s*(.*) | Player "(.*)" \(DEAD\) (id=(.*)) (.*) killed by Player/
I ran the above on a larger log file and the returned data was as below
[0] => 22:09:04 | Player "GigglingCobra52" (DEAD) (id=BE2ABB8084EEC781014AC8E6B5C88A5A90F855BF pos=<1658.8, 15056.8, 451.4>)[HP: 0] hit by Player "Cogito8434" (id=26DE70CAEF00AE579AF8CA21ED3F1648DB316F1E pos=<1659.4, 14990.8, 441.4>) into Head(0) for 36.7336 damage (Bullet_308WinTracer) with M70 Tundra from 66.7822 meters
22:09:04 | Player "GigglingCobra52" (DEAD) (id=BE2ABB8084EEC781014AC8E6B5C88A5A90F855BF pos=<1658.8, 15056.8, 451.4>) killed by Player "Cogito8434" (id=26DE70CAEF00AE579AF8CA21ED3F1648DB316F1E pos=<1659.4, 14990.8, 441.4>) with M70 Tundra from 66.7822 meters
I can now use the returned array data and pull info I need. Thanks again for everyone's help in guiding me how to figure this out
I have a log file and trying to find instances of 2 consecutive lines.
Here is an extract of a file :
21:12:44 | Player "MinecraftNerd8" (DEAD) (id=630DB6BBFCCC2E66508D086E78D202BFA4FB1FB5 pos=<5215.0, 13515.6, 204.5>)[HP: 0] hit by Player "sbog 9000" (id=EAD177E916EE7D01F6DC47C59EAF4802A6061420 pos=<5211.9, 13516.6, 203.8>) into Torso(11) for 35 damage (Bullet_12GaugePellets) with BK-43 from 3.32238 meters
21:12:44 | Player "MinecraftNerd8" (DEAD) (id=630DB6BBFCCC2E66508D086E78D202BFA4FB1FB5 pos=<5215.0, 13515.6, 204.5>) killed by Player "sbog 9000" (id=EAD177E916EE7D01F6DC47C59EAF4802A6061420 pos=<5211.9, 13516.6, 203.8>) with BK-43 from 3.32238 meters
21:12:44 | Player "RMuckey06" (DEAD) (id=1BE787EF788074C94B0FB22785EAD502E58240C1 pos=<5214.1, 13515.8, 203.8>)[HP: 0] hit by Player "sbog 9000" (id=EAD177E916EE7D01F6DC47C59EAF4802A6061420 pos=<5211.9, 13516.6, 203.8>) into Head(0) for 8.75 damage (Bullet_12GaugePellets) with BK-43 from 2.24871 meters
21:12:44 | Player "RMuckey06" (DEAD) (id=1BE787EF788074C94B0FB22785EAD502E58240C1 pos=<5214.1, 13515.8, 203.8>) killed by Player "sbog 9000" (id=EAD177E916EE7D01F6DC47C59EAF4802A6061420 pos=<5211.9, 13516.6, 203.8>) with BK-43 from 2.24871 meters
21:12:51 | Player "Cogito8434" (id=26DE70CAEF00AE579AF8CA21ED3F1648DB316F1E pos=<4629.4, 15078, 476.3>) regained consciousness
I am trying to return data for these 2 lines :
21:12:44 | Player "MinecraftNerd8" (DEAD) (id=630DB6BBFCCC2E66508D086E78D202BFA4FB1FB5 pos=<5215.0, 13515.6, 204.5>)[HP: 0] hit by Player "sbog 9000" (id=EAD177E916EE7D01F6DC47C59EAF4802A6061420 pos=<5211.9, 13516.6, 203.8>) into Torso(11) for 35 damage (Bullet_12GaugePellets) with BK-43 from 3.32238 meters
21:12:44 | Player "MinecraftNerd8" (DEAD) (id=630DB6BBFCCC2E66508D086E78D202BFA4FB1FB5 pos=<5215.0, 13515.6, 204.5>) killed by Player "sbog 9000" (id=EAD177E916EE7D01F6DC47C59EAF4802A6061420 pos=<5211.9, 13516.6, 203.8>) with BK-43 from 3.32238 meters
The 1st line represents the final hit as indicated by the [HP: 0] and the 2nd line immediately after which contains killed by Player, confirms this was the final hit as further hits after payer is dead will still be logged.
Here is the preg_match_all code I am using
/(.*?)Player "(.*)" (DEAD) (id=(.*) pos=<(.*)>)[HP: 0] hit by Player "(.*)" (id=(.*) pos=<(.*)>) into (.*) for (.*) damage (.*) with (.*) from (.*) meters\s*
(.*?)Player "(.*)" (DEAD) (id=(.*) pos=<(.*)>) killed by Player (.*)/
I'm trying this in the onlinephp.io sandbox but no matter what I change it still wont return any data.
Appreciate any help
Edit : Ive tried the below and now get data matches However its essential only lines with [HP: 0] are returned
/(.*?) | Player "(.*)" (DEAD) (id=(.*) pos=<(.*)>) [HP:0] hit by Player "(.*)" (id=(.*) pos=<(.*)>) into (.*) for (.*) damage (.*) with (.*) from (.*) meters\s(.*?)Player "(.*)" (DEAD) (id=(.*) pos=<(.*)>) killed by Player (.*)/
Fixed : Thanks to everyone for their help. The correct regex was
/(.*?)Player "(.*)" \(DEAD\)\ \(id=(.*) pos=<(.*)>\)\[HP: 0\] hit by Player "(.*)" \(id=(.*)\ pos=<(.*)>\) into (.*)\((.*)\) for(.*)damage (.*) with (.*) from (.*)\s*(.*) | Player "(.*)" \(DEAD\) (id=(.*)) (.*) killed by Player/
I ran the above on a larger log file and the returned data was as below
[0] => 22:09:04 | Player "GigglingCobra52" (DEAD) (id=BE2ABB8084EEC781014AC8E6B5C88A5A90F855BF pos=<1658.8, 15056.8, 451.4>)[HP: 0] hit by Player "Cogito8434" (id=26DE70CAEF00AE579AF8CA21ED3F1648DB316F1E pos=<1659.4, 14990.8, 441.4>) into Head(0) for 36.7336 damage (Bullet_308WinTracer) with M70 Tundra from 66.7822 meters
22:09:04 | Player "GigglingCobra52" (DEAD) (id=BE2ABB8084EEC781014AC8E6B5C88A5A90F855BF pos=<1658.8, 15056.8, 451.4>) killed by Player "Cogito8434" (id=26DE70CAEF00AE579AF8CA21ED3F1648DB316F1E pos=<1659.4, 14990.8, 441.4>) with M70 Tundra from 66.7822 meters
I can now use the returned array data and pull info I need. Thanks again for everyone's help in guiding me how to figure this out
Share Improve this question edited Mar 19 at 15:08 ChrisYates asked Mar 19 at 12:53 ChrisYatesChrisYates 1099 bronze badges 9 | Show 4 more comments1 Answer
Reset to default 4Fixed : Thanks to everyone for their help. The correct regex was
/(.*?)Player "(.*)" \(DEAD\)\ \(id=(.*) pos=<(.*)>\)\[HP: 0\] hit by Player "(.*)" \(id=(.*)\ pos=<(.*)>\) into (.*)\((.*)\) for(.*)damage (.*) with (.*) from (.*)\s*(.*) | Player "(.*)" \(DEAD\) (id=(.*)) (.*) killed by Player/
I ran the above on a larger log file and the returned data was as below
[0] => 22:09:04 | Player "GigglingCobra52" (DEAD) (id=BE2ABB8084EEC781014AC8E6B5C88A5A90F855BF pos=<1658.8, 15056.8, 451.4>)[HP: 0] hit by Player "Cogito8434" (id=26DE70CAEF00AE579AF8CA21ED3F1648DB316F1E pos=<1659.4, 14990.8, 441.4>) into Head(0) for 36.7336 damage (Bullet_308WinTracer) with M70 Tundra from 66.7822 meters
22:09:04 | Player "GigglingCobra52" (DEAD) (id=BE2ABB8084EEC781014AC8E6B5C88A5A90F855BF pos=<1658.8, 15056.8, 451.4>) killed by Player "Cogito8434" (id=26DE70CAEF00AE579AF8CA21ED3F1648DB316F1E pos=<1659.4, 14990.8, 441.4>) with M70 Tundra from 66.7822 meters
[1] => 22:12:08 | Player "Cogito8434" (DEAD) (id=26DE70CAEF00AE579AF8CA21ED3F1648DB316F1E pos=<1656.3, 15053.1, 444.8>)[HP: 0] hit by Player "GigglingCobra52" (id=BE2ABB8084EEC781014AC8E6B5C88A5A90F855BF pos=<1654.7, 15052.8, 444.8>) into Torso(12) for 29.0213 damage (Bullet_556x45) with M4-A1 from 1.57712 meters
22:12:08 | Player "Cogito8434" (DEAD) (id=26DE70CAEF00AE579AF8CA21ED3F1648DB316F1E pos=<1656.3, 15053.1, 444.8>) killed by Player "GigglingCobra52" (id=BE2ABB8084EEC781014AC8E6B5C88A5A90F855BF pos=<1654.7, 15052.8, 444.8>) with M4-A1 from 1.57712 meters
I can now use the returned array data and pull info I need. Thanks again for everyone's help in guiding me how to figure this out
(...)
creates a capturing group; if you want the brackets to be meant literally, you need to escape them. And for further testing, might I recommend regex101 – C3roe Commented Mar 19 at 13:02(DEAD)
need to be escaped as\(DEAD\)
so that they count as a literal character and not a meta one: regex101/r/yNUrCZ/1 – Chris Haas Commented Mar 19 at 13:56