return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>php - PREG_MATCH_ALL not returning matches - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - PREG_MATCH_ALL not returning matches - Stack Overflow

programmeradmin4浏览0评论

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
  • 5 First thing that catches the eye: (...) 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
  • Are you 100% certain that the two log lines always appear literally one after the other, with absolutely zero chance of another log entry being added in between the two? – Chris Haas Commented Mar 19 at 13:09
  • 100% .. those 2 lines which is the initial; HP: 0 is always followed by the line containing killed by. – ChrisYates Commented Mar 19 at 13:11
  • Have added an edit as am getting data returned now although its not restricting to lines where it has HP: 0 – ChrisYates Commented Mar 19 at 13:23
  • 1 As noted, parentheses such as (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
 |  Show 4 more comments

1 Answer 1

Reset to default 4

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

[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

发布评论

评论列表(0)

  1. 暂无评论