#!/usr/bin/perl
use strict;
use warnings;
use Encode;
use utf8;
use open ':utf8';
binmode STDIN, ":utf8";
binmode STDOUT, ":utf8";
my $query = shift @ARGV;
$query = Encode::decode_utf8($query) if not utf8::is_utf8($query);
my %token;
foreach my $i (grep {not /^\s*$/} split(/[\(\)\&\|\!]+/, $query)) {
$token{$i} = 1;
}
while (<>) {
my %match;
foreach my $i (keys %token) {
$match{$i} = 1 if /$i/;
}
my $pat = $query;
$pat =~ s/([^\(\)\&\|\!]+)/$match{$1}?1:0/ge;
print if eval "$pat";
}
% cat test.txt あいうえお ああいおお おうえい うえおけ あいうえおけ % ./logrep.pl '(あい|うえ)&お&!(か|き|け)' test.txt あいうえお ああいおお おうえい
perl -ne 'print if /^(?=.*abc)(?=.*xyz)/' abcddddxyz → o xyzzzzabcd → o abcdefghij → x qrstuvwxyz → x
| 午前半休 | 1345-1745 |
| 午後半休 | 900-1300 |