topical media & game development

talk show tell print

basic-regex-26-RegexTester.pl / pl



  #!/usr/bin/perl -w
  use strict;
  print "This is a simple Regular Expression Tester.\n";
  print "First, enter the pattern you want to test.\n";
  print "Remember NOT to escape metacharacters like \\d with an extra \\ when you supply a pattern on the command line.\n";
  print "Enter your pattern here: ";
  my myPattern = <STDIN>;
  chomp(myPattern);
  print "The pattern being tested is 'myPattern'.";
  print "Enter a test string:\n";
  while (<>)
  {
   chomp();
   if (/myPattern/)
   {
    print "Matched '&' in '_'\n";
    print "\nEnter another test string (or Ctrl+C to terminate):";
   }
   else
   {
    print "No match was found for 'myPattern' in '_'.\n";
    print "\nEnter another test string (or Ctrl+C to terminate):";
   }
  }


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.