PHPBuilder - Regular Expressions Testing Tool

RSS Twitter

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']) {
	if (eregi($pattern,$string))
		echo "$pattern pattern matches \"$string\"";
		echo "$pattern pattern does not match \"$string\"";
<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">

Comment and Contribute

Your comment has been submitted and is pending approval.

Tom Kredo



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