#!/usr/bin/perl # Josh Hursey # April 3, 2003 use strict; my $argc = scalar(@ARGV); my $expr; for(my $i=0; $i < $argc; ++$i){ $expr .= $ARGV[$i] . " "; } chop($expr); print "Your Expression:<$expr>\n"; print "----------------\n"; my $example = "hot cross buns"; print "Example from Programming Perl Book:\n"; print "\t$example\n"; if($example =~ /cross/){ print "Matched: <$`> $& <$'>\n"; print "Left: <$`>\n"; print "Match: <$&>\n"; print "Right: <$'>\n"; } print "----------\n"; print "Determine if x is in your expression\n"; if($expr =~ /x/){ print "\tYep I found one!\n"; } else { print "\tNope, No x's in this one!\n"; } print "----------\n"; print "Determine if x or y is in your expression\n"; if($expr =~ /[xy]/){ print "\tYep I found one!\n"; } else { print "\tNope, No x's or y's in this one!\n"; } print "----------\n"; print "Does it start with x followed by at least one y?\n"; if($expr =~ /^xy+/){ print "\tYep!\n";} else { print "\tNope!\n"; } print "----------\n"; print "It is a digit or series of digits then\n"; if($expr =~ /^[0-9]+$/){ print "\tYep!\n";} else { print "\tNope!\n"; } print "----------\n"; print "Is it just one and only one word thus\n"; if($expr =~ /^(thus)$/){ print "\tYep!\n";} else { print "\tNope!\n"; } print "----------\n"; print "Take this expression:\n"; my $story = "Once upon a time there was a little rabbit..."; print "\t<$story>\n"; print "Replace all of the 'little's with 'BIG's\n"; $story =~ s/little/BIG/; print "Now heres a story:\n"; print "\t<$story>\n"; print "----------\n"; print "Hope this helps a bit, take a look on the web, \n"; print "and don't be afraid to experament in little scripts.\n"; print "That is the best way to learn Regular Expressions.\n"; print "----------\n"; exit;