#!/share/bin/perl #define the pattern in a doubly quoted string #Examples # input "[0-9]+" (should match all input lines that contain some digits) # input "^[0-9]+" (should match lines that start with digits) # input "[0-9]+$" (lines ending with digits,) # input "^[0-9]{13,16}$" (a bankcard number, 13 to 16 digits with nothing else in line) # input "\d{13,16}" (a bankcard number possibly embedded in larger line) # If you define patterns as text strings in the code, then you need # to remember to double any \ characters # $pat = "\\d{13,16}"; print "Enter pattern string : "; $pat = ; chomp($pat); #let user enter data to test pattern print "Enter test string : "; while() { if( /quit/i ) { last; } if( /$pat/ ) { print "\tInput matched\n"; #uncomment if looking for subexpression within match # print "\t\tThe (first) matched subexpression was $1\n"; # print "\t\tThe (second) matched subexpression was $2\n"; } else { print "\tNo match\n"; } print "Enter next test string : "; }