Skip to content

Instantly share code, notes, and snippets.

@sekia
Created March 6, 2012 09:46
Show Gist options
  • Save sekia/1985363 to your computer and use it in GitHub Desktop.
Save sekia/1985363 to your computer and use it in GitHub Desktop.
ピカチュウっぽいセリフの正規表現を作るスクリプト ref: http://qiita.com/items/3030
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Regexp::Optimizer;
=for comment
Output:
(?^u:(?:ピ(?:カ(?:ピ(?:カチューッ?|[ーッィ])?|ッ(?:チュ[ーッ]?)?|、ピカチュウ[ーッ]?|[ーァ])?|ッ(?:ピカチュウ[ーッ]?|カピカチュウ[ーッ]?)?|ー(?:カ(?:ピカ[ーッァ]?|[ーッァ])?)?|ィ(?:カ(?:ァ(?:ーチューウ[ーッ]?)?|[ーッ])?)?|ピピ[ーッィ]?)?|ビガ(?:ーッ?|ジューッ?)))
=cut
chomp(my @pika_words = <DATA>);
my @additionals = map {
my @ws;
push @ws, $_ . 'ー' unless /ー$/;
push @ws, $_ . 'ッ' unless /ッ$/;
push @ws, $_ . 'ァ' if /カ$/;
push @ws, $_ . 'ィ' if /ピ$/;
@ws;
} @pika_words;
my $opt = Regexp::Optimizer->new;
my $re = $opt->list2re(@pika_words, @additionals);
binmode STDOUT, ':utf8';
print $re, "\n";
# Pikachu-like lines below are taken from
# http://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q1222520562 and
# modified.
__DATA__
ピカピ
ピッピカチュウ
ピカピカチュー
ピーカピカ
ピーカ
ピカ
ビガー
ピィカ
ピピピ
ピカッチュ
ピッカピカチュウ
ピカ、ピカチュウ
ピィカァーチューウ
ビガジュー
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment