Ask a server log for the regular how to write

Source: Internet
Author: User
2013-06-23 04:33:51 w3svc1539885 198.56.185.162 get/robots.txt-80-66.249.75.65 mozilla/5.0+ (compatible;+googlebot/ 2.1;++http://www.google.com/bot.html) 404 0 2

I would like to match the date 2013-06-23/time 04:33:51/server ip198.56.185.162/file address robots.txt/spider ip66.249.75.65/Spider information mozilla/5.0+ (compatible; +googlebot/2.1;++http://www.google.com/bot.html)/Status code 404 0 2/, how exactly does this match?


Reply to discussion (solution)

It's best to give a specific example, and then show the results you expect, and your question indicates that you don't understand

It's best to give a specific example, and then show the results you expect, and your question indicates that you don't understand
The code is a specific example, I want to take the value of the following, just want to write a sentence regular match, with Pregmatch this generation of an array and then I do something else.

I think the format of this date should be fixed, you can split them by a space, for example

$log = ' 2013-06-23 04:33:51 w3svc1539885 198.56.185.162 get/robots.txt-80-66.249.75.65 mozilla/5.0+ (COMPATIBLE;+GOOGL ebot/2.1;++http://www.google.com/bot.html) 404 0 2 '; Var_dump (Explode (", $log)); /**array {  [0]=>  string (Ten) "2013-06-23"  [1]=>  string (8) "04:33:51"  [2]=>  String ("w3svc1539885"  [3]=> string "  198.56.185.162"  [4]=>  string (3) "GET"  [5]= >  string (one) "/robots.txt"  [6]=>  string (1) "-"  [7]=>  string (2) "  [8]= >  string (1) "-"  [9]=>  string (66.249.75.65) "  [10]=> string"  mozilla/5.0+ (compatible;+googlebot/2.1;++http://www.google.com/bot.html) "  [11]=>  string (3)" 404 "  [12]= >  string (1) "0"  [13]=>  string (1) "2"}*/

I think the format of this date should be fixed, you can split them by a space, for example

$log = ' 2013-06-23 04:33:51 w3svc1539885 198.56.185.162 get/robots.txt-80-66.249.75.65 mozilla/5.0+ (COMPATIBLE;+GOOGL ebot/2.1;++http://www.google.com/bot.html) 404 0 2 '; Var_dump (Explode (", $log)); /**array {  [0]=>  string (Ten) "2013-06-23"  [1]=>  string (8) "04:33:51"  [2]=>  String ("w3svc1539885"  [3]=> string "  198.56.185.162"  [4]=>  string (3) "GET"  [5]= >  string (one) "/robots.txt"  [6]=>  string (1) "-"  [7]=>  string (2) "  [8]= >  string (1) "-"  [9]=>  string (66.249.75.65) "  [10]=> string"  mozilla/5.0+ (compatible;+googlebot/2.1;++http://www.google.com/bot.html) "  [11]=>  string (3)" 404 "  [12]= >  string (1) "0"  [13]=>  string (1) "2"}*/


I think the format of this date should be fixed, you can split them by a space, for example
$log = ' 2013-06-23 04:33:51 w3svc1539885 198.56.185.162 get/robots.txt-80-66.249.75.65 mozilla/5.0+ (COMPATIBLE;+GOOGL ebot/2.1;++http://www.google.com/bot.html) 404 0 2 '; Var_dump (Explode (", $log)); /**array {  [0]=>  string (Ten) "2013-06-23"  [1]=>  string (8) "04:33:51"  [2]=>  String ("w3svc1539885"  [3]=> string "  198.56.185.162"  [4]=>  string (3) "GET"  [5]= >  string (one) "/robots.txt"  [6]=>  string (1) "-"  [7]=>  string (2) "  [8]= >  string (1) "-"  [9]=>  string (66.249.75.65) "  [10]=> string"  mozilla/5.0+ (compatible;+googlebot/2.1;++http://www.google.com/bot.html) "  [11]=>  string (3)" 404 "  [12]= >  string (1) "0"  [13]=>  string (1) "2"}*/

But the server log is not every line is like this, there are many # beginning, so just want to do a regular filter out the other format.

This point can't be wasted.

Log files are generally very large
You need to read through the loop in a row, split into arrays

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.