PHPBuilder - Regular Expressions Testing Tool



RSS Twitter
Snippets Other

Regular Expressions Testing Tool

by: Tom Kredo
|
February 16, 2003

Version: 1

Type: Full Script

Category: Other

License: GNU General Public License

Description: Allows you to test the validity of a Regular Expression against a sample string. Great for learning how to use RegEx or to create and test new ones. This program is written in PHP.



<? # Program to test Regular Expressions  by Tom Kredo 2003
# Example Test for valid Zip Code:  String= 14610-1234 Pattern=^([0-9]{5})(-[0-9]{4})?$

$self=$_SERVER['PHP_SELF']; # Get the Global for who we are

if($_POST['pattern']) {
	$pattern=$_POST['pattern'];
	$string=$_POST['string'];
	if (eregi($pattern,$string))
		echo "$pattern pattern matches \"$string\"";
	else
		echo "$pattern pattern does not match \"$string\"";
	}
?>
<html>
<body>
<h1>Testing Regular Expressions</h1>
<form action=<? echo "$self"; ?> method=POST>
String: <input type=text name="string" value="<? echo "$string"; ?>" size=30><br><br>
RegEx Pattern: <input type=text name="pattern" value="<? echo "$pattern"; ?>" size=30><br><br>
<input type=submit value="Test Pattern" name="Submit">
</form>
</body></html>

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Tom Kredo

Comment:



Comment:

(Maximum characters: 1200). You have characters left.