#! /usr/bin/perl

use strict;
use warnings;

# compares the command line argument to three patterns

my $userStr = $ARGV[0];


# any non-empty string that does not contain a newline
my $noNewline = '^[^\n]+$';

# an optional +/-
# followed by one or more 1-9's
# followed by zero or more 0-9's
my $noLeadZero = '^[+-]?[1-9]+[0-9]*$';

#   ^\" so it begins with a "
#   \"$ so it ends with a "\
#   [^\"]* so inside can be anything except a "
my $quotedStr = '^\"[^\"]*\"$';

print "start of user string --> \'\n\' $userStr";
print "\' <-- end of user string\n";

print "\nTesting against no-newlines pattern $noNewline\n\n";
if ($userStr =~ $noNewline) {
   print "Matched!\n\n";
} else {
   print "No match\n\n";
}

print "Testing against no-leading-zeroes integer pattern $noLeadZero\n";
if ($userStr =~ $noLeadZero) {
   print "Matched!\n\n";
} else {
   print "No match\n\n";
}

print "Testing against string literal pattern $quotedStr\n";
if ($userStr =~ $quotedStr) {
   print "Matched!\n\n";
} else {
   print "No match\n\n";
}

1
