We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
/m
/s
split(/\n/, $Log)
#!/usr/bin/env perl use strict; use warnings; my $Log1 = '192.0.2.125 - - [17/Jul/2020:07:01:22 +0900] "GET /index.html HTTP/1.1" 200 7697 "https://twitter.com/" "Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Mobile/15E148 Safari/604.1" TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384'; # /m, /sが出るなら$Log1と結合して使う my $LogX = '203.0.113.55 - - [18/Jul/2020 16:25:02 +0900] "POST /contact HTTP/1.1" 200 3654 "http://example.jp/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36" "-"'; printf("Log1 = %s\n", $Log1); # パターンマッチ print "OK: Mac\n" if $Log1 =~ /Mac/; # Like Mac OS X) print "OK: Windows\n" if $Log1 !~ /Windows/; # 任意の一文字 print "OK: [Xx]\n" if $Log1 =~ /[Xx]/; # index.html, Mac OS X # 任意の一文字(否定) print "OK: [Qq]\n" if $Log1 !~ /[Qq]/; # 任意の一文字(連続) print "OK: [x-z]\n" if $Log1 =~ /[x-z]/; # index.html, Mac OS X, Mozilla print "OK: [0-9]\n" if $Log1 =~ /2020:0[0-9]:/; # 00-09 # 任意の一文字(応用) print "OK: [Ii]ndex\n" if $Log1 =~ /[Ii]ndex/; print "OK: [Hh][Tt][Mm][Ll]\n" if $Log1 =~ /[Hh][Tt][Mm][Ll]/; # ワイルドカード print "OK: Ju.\n" if $Log1 =~ /Ju./; # Jun, Jul print "OK: TLSv1.[012]\n" if $Log1 =~ /TLSv.[0-2]/; # 量指定子`?` print "OK: https?:\n" if $Log1 =~ /https?:/; # 量指定子`+` print "OK: Apple\n" if $Log1 =~ /Ap+le/; # Apple, Apppppple, Aple # 量指定子`*` # 柔軟な量指定子 print "OK: +0900\n" if $Log1 =~ /[0-9]{4}/; # +0900, 2020 print "OK: /2020\n" if $Log1 =~ /2[0-9]{3}/; # 2020 print "OK: /2020\n" if $Log1 =~ /2[0-9]{2,}/; # 200, 2020, AES256 # マッチした文字列の取得 if( $Log1 =~ /iPhone OS (.+) like Mac/ ) { printf("iOS version is %s\n", $1); # 13_1 } if( $Log1 =~ /2020:(.+):(.+):([0-9]{2}+) / ) { printf("アクセスされた時間は%d時%d分%d秒です\n", $1, $2, $3); } if( $Log1 =~ /TLSv(.+?) / ) { printf("TLS version is %s\n", $1); } # 置換 my $Log2 = $Log1; $Log2 =~ s/192.0.2.125/192.***.***.***/; printf("Log1 with masked IP Address(1) = \n%s\n", $Log2); if( $Log1 =~ /iPhone OS (.+) like Mac/ ) { my $v = $1; $v =~ s/_/./; printf("iOS version is %s\n", $v); # 13.1 } # メタ文字 if( $Log1 =~ /(\d{4}):(\d\d):(\d+):([0-9]{2}+) / ) { printf("アクセスされた時間は%d年%d時%d分%d秒です\n", $1, $2, $3, $4); } if( $Log1 =~ /(twitter|facebook|instagram).com/ ) { printf("%sからきました\n", ucfirst $1); } if( $Log1 =~ /(index|top)[.](?:html|php|cgi)/ ) { printf("トップページ(%s)にアクセスがありました\n", $1); } if( $Log1 =~ /[+](\d{2})\d{2}/ ) { printf("時差は%d時間です\n", int $1); } # アンカー my $Log3 = $Log1; $Log3 =~ s/^\d{1,3}[.]\d{1,3}/***.***/; printf("Log1 with masked IP Address(1) = \n%s\n", $Log3); # 区切り文字 if( $Log1 =~ m|17/Jul/2020| ) { print "7月17日にアクセスがありました\n"; } if( $Log1 =~ m{/(?:Jun|Jul)/2020} ) { print "6月または7月にアクセスがありました\n"; } # Modifiers my $Log4 = $Log1; $Log4 =~ s/iPhone/Android/g; printf("Log4 = %s\n", $Log4); print "OK: html/i\n" if $Log1 =~ /html/i;
The text was updated successfully, but these errors were encountered:
No branches or pull requests
/m
,/s
が出てくるなら複数行のログを使ってsplit(/\n/, $Log)
で配列に分割したりThe text was updated successfully, but these errors were encountered: