正規表式示

2013-08-26 11:52

$string =~ m/$patten/ $string =~ m{$patten} $string =~ m|$patten| $string =~ m!$patten! $string =~ /$patten/ 

 

 

my $answer = "monger"; until ((my $patten = ) =~ /$answer/) { # 持續進行,直到使用者輸入含有 monger 的字串 print "wrong\n";   # 在這裡,表示比對失敗 };

 

 

my $answer = "mo*r";  			# 使用量詞
while (1) {    				# 所以其實是無限迴圈
    if ((my $patten = ) =~ /$answer/) {  # 判斷是否比對成功
        print "*match*\n";
    } else {
        print "*not match*\n";
    }
};

 

 

my $answer = "mo{2,4}r";  # 新的比對樣式
while (1) {
    if ((my $patten = ) =~ /$answer/) {
        print "*match*\n";
    } else {
        print "*not match*\n";
    }
};

 

 

my $answer = "(wow)+";  # 新的比對樣式
while (1) {
    if ((my $patten = ) =~ /$answer/) {
        print "*match*\n";
    } else {
        print "*not match*\n";
    }
};