2017年4月12日水曜日

開発環境

Think Perl 6: How to Think Like a Computer Scientist (Laurent Rosenfeld(著)、Allen B. Downey(著)、Oreilly & Associates Inc)のPart 1(Starting with the basics)、Chapter 7(Strings)の Regular expressions (regexes) の Exercises on regexesを取り組んでみる。

Regular expressions (regexes) の Exercises on regexes

コード(Emacs)

#!/usr/bin/env perl6
# -*- coding: utf-8 -*-

say '1.';
say ~$0 if 'abcde123457890abcde' ~~ /(<[0..9]>+)/;

say '2.';
say ~$0 if 'abcde1234567890abcde' ~~ /(<[0..7]>+)/;

say '3.';
say ~$0 if 'perl6 python javascript' ~~ /(\w+)/;

say '4.';
say ~$0 if 'perl6 abcde python javascript' ~~ /\W(a\w+)/;

say '5.';
say ~$0 if 'perl6 abcde python javascript' ~~ /\W(<[a..z]>+\w*)/;

say '6.';
say ~$0 if 'perl6 Abcde python javascript' ~~ /\W(:i<[a..z]>+\w*)/;

say '7.';
say ~$/ if 'perl6 Abcde python javascript aabcde' ~~ /(:i<[a..z]>)$0/;

say '8.';
say ~$/[1] if 'perl6 aabcde Abcde python javascript abbcde' ~~ m:g/(:i<[a..z]>)$0/;

入出力結果(Terminal, REPL)

$ ./sample_regexes.pl
1.
123457890
2.
1234567
3.
perl6
4.
abcde
5.
abcde
6.
Abcde
7.
aa
8.
bb
$

0 コメント:

コメントを投稿