Click here to Skip to main content
15,886,724 members
Articles / Web Development / HTML

JavaScript Regular Expression Tester

Rate me:
Please Sign up or sign in to vote.
4.67/5 (15 votes)
19 Oct 2004CC (ASA 2.5)5 min read 112.5K   1.5K   30  
A tool for testing regular expressions in JavaScript.
<!--
	Copyright 2003,2004 Anthony M. Humphreys <anthony@humphreys.org>
-->
<HTML>
	<HEAD>
		<SCRIPT LANGUAGE="JavaScript"><!--
/*
 * Copyright 2003,2004 Anthony M. Humphreys <anthony(at)humphreys.org>
 *
 * Permission is granted to use and modify this script for any purpose,
 * provided that this credit header is retained, unmodified, in the script.
 *
 */

function copyUp() {
	window.top.RegExTest.theExpression = document.local.TheExpression.value;
	if (document.local.RexExType[0].checked) {
		window.top.RegExTest.regExType = 'literal';
	} else {
		window.top.RegExTest.regExType = 'string';
	};
};
function copyDown() {
	document.local.TheExpression.value = window.top.RegExTest.theExpression;
	if (window.top.RegExTest.regExType == 'literal') {
		document.local.RexExType[0].checked = true;
	} else {
		document.local.RexExType[1].checked = true;
	};
};
// -->
		</SCRIPT>
	</HEAD>
	<BODY LEFTMARGIN="0" RIGHTMARGIN="0" TOPMARGIN="3" ONLOAD="copyDown();" ONUNLOAD="copyUp();" ONBLUR="copyUp();" ONMOUSEOUT="copyUp();">
		<FORM NAME="local" ID="local" ONSUBMIT="return false;">
			<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
				<TR VALIGN="top">
					<TD>RegEx:</TD>
					<TD WIDTH="99%"><TEXTAREA COLS="40" STYLE="width: 100%;" ROWS="3" NAME="TheExpression" ID="TheExpression" ONCHANGE="copyUp();" ONMOUSEOUT="copyUp();" ONBLUR="copyUp();"></TEXTAREA></TD>
					<TD>
						<TABLE>
							<TR>
								<TD><INPUT TYPE="radio" NAME="RexExType" ID="RexExType1" VALUE="literal" ONCHANGE="copyUp();"></TD>
								<TD><LABEL FOR="RexExType1">Literal</LABEL></TD>
							</TR>
							<TR>
								<TD><INPUT TYPE="radio" NAME="RexExType" ID="RexExType2" VALUE="string" ONCHANGE="copyUp();"></TD>
								<TD><LABEL FOR="RexExType2">String</LABEL></TD>
							</TR>
						</TABLE>
					</TD>
				</TR>
			</TABLE>
		</FORM>
	</BODY>
</HTML>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Creative Commons Attribution-ShareAlike 2.5 License


Written By
Canada Canada
I am a former Witango (aka Tango from Pervasive/Everyware) programmer.
Now programming is my avocation.

Comments and Discussions