zoukankan      html  css  js  c++  java
  • 第7章: 正则表达式

      

    #! /usr/bin/perl
    use strict;
    use warnings;

    print " ----------------------------------simple_pattern_metacharacter_quantifier-------------------------- ";
    $_ = "asteriskasterisk hash access unpack_func";
    for (/as.*e/){
        print "matched. ";
    }
    for (/(asterisk)+/){
        print "matched*2. ";
    }
    for(/unpack.*|lvalue|alignment/){
        print "matched*3. ";
    }
    my @escaped = "asteriskasterisk hash access unpack_func";
    print @escaped;
    print "@escaped";
    foreach(@escaped){
        print $_;
    }
    print " ";
    print $escaped[0];
    print " ";
    unless( $escaped[1] ){
        print "$escaped[1] is undef.";
    }
    print " ----------------------------------simple_pattern_metacharacter_quantifier-------------------------- ";

    print " ----------------------------------_alternative_-------------------------- ";
    print $_." ";
    for(/access (unpack|indices)_func/){
        print "matched*4. ";
    }
    print " ----------------------------------_alternative_-------------------------- ";

    print " ----------------------------------_character_class-------------------------- ";
    $_ = 'z';
    for(/[a-cw-z]/){
        print "matched*5. ";
        print "00";
        print " ";
        print "177";
    }
    $_ = "The HAL-9000 requires 8 authorization.";
    if(/HAL-[0-9]+/){
        print "HAL computers mentioned."
    }
    print " ----------------------------------_character_class-------------------------- ";

    print " ----------------------------------_character_class_shortcut-------------------------- ";
    if(/HAL-d+/){
        print "HAL computers mentioned. matched*5. ";
    }
    if(/requires w authorization/){
        print "matched*6. ";
    }
    print " ----------------------------------_character_class_shortcut-------------------------- ";

    print " ----------------------------------exercise_ch7_-------------------------- ";
    $_ = "aligning Alignrick or veralign.";
    if(/align/){
        print "matched*7. ";
    }
    open ARROW_NOTATION, "< file_4_ex_ch7.txt";
    my $counter = 8;
    while(<ARROW_NOTATION>){
        chomp;
        my $arraow_syntax = $_;
        #for(/[a|A]lign/){
        for(/./){
            print "matched*$counter. ";
            $counter++;
            print $arraow_syntax." ";
        }
    }
    close ARROW_NOTATION;
    print " ----------------------------------exercise_ch7_-------------------------- ";

    print " ----------------------------------exercise_ch7_4-------------------------- ";
    while(<>){
        if(/[A-Z][a-z]+/){
            print $_." " ;
        }
        if(/[a-z][A-Z]/){
            print $_." " ;
        }
    }
    print " ----------------------------------exercise_ch7_4-------------------------- ";























  • 相关阅读:
    在美国贩卖早餐的小摊贩
    随感
    业内人士称游资3年前开始准备炒作糖价
    许志:量化宽松在即 美元迎来关键一周
    9月17日  逾200亿资金净流出 农行轰然长阴 好笑
    9月热钱流入环比加速 多为投机性资金
    错过了多次捞钱的机会
    20101012 期货盘面暴跌,亏损持仓
    致歉申明,现在《微电子工程师》可以正常下载了
    SemiId半导体型号识别器1.0发布
  • 原文地址:https://www.cnblogs.com/books2read/p/11132105.html
Copyright © 2011-2022 走看看