LoginSignup
12
12

More than 5 years have passed since last update.

ピカチュウっぽいセリフの正規表現を作るスクリプト

Posted at

参照: https://twitter.com/chokudai/status/176877685916712962

自分で書くのが面倒だったのでコンピュータにやってもらいました。

pika.pl
#!/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__
ピ
ピカピ
ピッピカチュウ
ピカピカチュー
ピーカピカ
ピーカ
ピカ
ビガー
ピィカ
ピピピ
ピカッチュ
ピッカピカチュウ
ピカ、ピカチュウ
ピィカァーチューウ
ビガジュー
12
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
12