www.perl.com
Perl Programming
Regular Expressions
  • Regexes perform textual pattern matching
  • Regexes ask:
    Does a string...
    • ...contain the letters "dog" in order?
    • ...not contain the letter "z"?
    • ...begin with the letters "Y" or "y"?
    • ...end with a question mark?
    • ...contain only letters?
    • ...contain only digits?

        my $string = "Did the fox jump over the dogs?";
        print "1: $string\n" if $string =~ /dog/;          # matches
        print "2: $string\n" if $string !~ /z/;            # matches
        print "3: $string\n" if $string =~ /^[Yy]/;
        print "4: $string\n" if $string =~ /\?$/;          # matches
        print "5: $string\n" if $string =~ /^[a-zA-Z]*$/;
        print "6: $string\n" if $string =~ /^\d*$/;
      
Previous http://stuff.mit.edu/iap/perl/