#!/usr/bin/perl -w

use CGI;

# create CGI object
$q          = new CGI;

# extract incoming POST data from STDIN
$text       = $q->param('text');
$expression = $q->param('expression');

chomp($text);
chomp($expression);

$out = $text;
$result = "";

if ($expression !~ m/[\w{1,}|\.]/ || $expression eq '')
{
	$result = "Unable to handle expression."
}
elsif ($text =~ m/($expression)/m )
{
	$out = $text;
	$result = "m\/<b>$expression</b>\/ matches \'<span class=\"raise\">$1</span>\'.";
}
else
{
	$result = "Found no match.";
}


print <<FORM;
Content-type: text/html\n\n


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>
Regular Exression Tester</title>
<style type="text/css">
\@import "http://people.cs.uchicago.edu/~sterner/cs101/testpl/regex/teaching.css";

.left   { float: left; width: 30em; }
#result { border: solid 1px black; padding: 0.5em; width: 30em; }

</style>
</head>
<body>
<h2>Regular Expression Matching</h2>
<form method="post" action="http://www.people.cs.uchicago.edu/~sterner/cs101/testpl/regex/regex_match.pl" id="reg_ex_match">
<div class="left">
<h4>Text:</h4>
<input type="text" name="text" value="$text" size="30" maxlength="30">

</div>
<div>
<h4>Regular Expression:</h4>
m/<input type="text" name="expression" value="$expression" size="30" maxlength="30" />/
</div>
<br />
<div class="left">
<span  id="result">
$result
</span>
</div>
<div class="center"><input type="submit" name="submit" value="Submit" />
</div>

<br />


</form>
 
</body>
</html>


FORM


