開発環境
- OS X Mavericks - Apple(OS)
- BBEdit - Bare Bones Software, Inc., Emacs (Text Editor)
- Perl (プログラミング言語)
初めてのPerl 第6版 (Randal L. Schwartz (著)、brian d foy (著)、Tom Phoenix (著)、近藤 嘉雪 (翻訳)、オライリージャパン)、8章(正規表現によるマッチ)の8.10(練習問題)3.を解いてみる。
その他参考書籍
8.10(練習問題)3.
コード(BBEdit, Emacs)
sample190_3.pl
#!/usr/bin/env perl # use diagnostics; use strict; use warnings; use 5.016; use utf8; binmode STDIN, ':utf8'; binmode STDOUT, ':utf8'; binmode STDERR, ':utf8'; while (<>) { chomp; if (/\b(.*a)\b/) { say "Matched: |$`<$&>$'|"; say "\$1 contains '$1'"; } else { say "No match: |$_|"; } }
入出力結果(Terminal)
$ ./sample190_3.pl temp.txt No match: |A| Matched: |<a>| $1 contains 'a' Matched: |<kamimura>'s blog| $1 contains 'kamimura' Matched: |<http://sitekamimura>.blogspot.com| $1 contains 'http://sitekamimura' No match: |KMI| Matched: |<http://www.mkamimura>.com| $1 contains 'http://www.mkamimura' No match: |frederick| Matched: |<Wilma>| $1 contains 'Wilma' No match: |Alfred| Matched: |<Wilma>| $1 contains 'Wilma' No match: |fred flintstone| Matched: |<Wilma>| $1 contains 'Wilma' No match: |Wilmaerick| Matched: |<AlWilma>| $1 contains 'AlWilma' Matched: |<Wilma> flintstone| $1 contains 'Wilma' No match: |Mr. Slate | No match: |Mississippi| No match: |Bamm-Bamm | Matched: |<wilama>| $1 contains 'wilama' No match: |barney| Matched: |<Fred and Wilma>| $1 contains 'Fred and Wilma' Matched: |<Wilma> and Fred| $1 contains 'Wilma' Matched: |<Fred and Wilma> | $1 contains 'Fred and Wilma' Matched: |<Wilma> and Fred| $1 contains 'Wilma' Matched: |<Fred&Wilma>| $1 contains 'Fred&Wilma' No match: |Mrs. Fred Flintstone | No match: |I saw Fred yesterday| No match: |I, Fred!| No match: |Z| Matched: |<llama>| $1 contains 'llama' No match: |fred| $
0 コメント:
コメントを投稿