IT 441: Network Services Administration
Class #13 Exercise

Complete by: 4/12/2018


Log in to users.cs.umb.edu

Regexes - The i option and the . Meta-Character

perl>  $string = "foobar" ;

perl>  if ($string =~ /foo/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /Foo/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /BAR/i) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /foo.ar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /.oo.ar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /foo..ar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

Regexes - The ? Meta-Character

perl>  if ($string =~ /foob?ar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /foobf?ar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /foob?far/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /foo.?ar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /foob.?ar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /foob.?far/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

Regexes - The * Meta-Character

perl>  if ($string =~ /fo*bar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /foo*bar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /fooo*bar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /foooo*bar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /foobf*ar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /foo.*bar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /f.*ar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

Regexes - The + Meta-Character and Specific Character Counts

perl>  if ($string =~ /fo+bar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /foo+bar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /fo{2}bar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /fo{1,3}bar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /fooo+bar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /foob+ar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /foo.+bar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /f.+ar/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /fo+.+r/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

Regexes - Special Characters and Cases

perl>  $string = "3.14159" ;

perl>  if ($string =~ /3.14/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /3214/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /3@14/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /3\.14/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ("3214" =~ /3\.14/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /3\.1\d*9/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /3\.1\d+9/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /3\.1\d+/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /3\.[1-5]+9/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

perl>  if ($string =~ /3\.14[13579]+/) { print "Match!\n" ; } else { print "Sorry, no match.\n" ; }

End the Perl Session

perl>  exit

End the script session

Use the exit command. You should then have a file called typescript in your current working directory.