x
<html>
<head>
<title>JS tutorial</title>
<style type="text/css">
body {
margin:10px 10px; padding:3px;
background-color:#345; color:#aaa;
font-family:"Arial", serif;
}
input {
font-family:"Lucida", serif; font-size:1.2em; color:#555; text-align:center;
}
#res {
padding:3px 4px; border:1px solid gray; color:#888;
}
</style>
<script type="text/javascript">
var pattern = /(a(b(cd)?)?)?/gi;
var text = "abcdef";
var match = pattern.exec(text);
document.write(pattern + "<br />");
document.write(text);
function expressionTest() {
if (pattern.test(text)) {
res.innerHTML = "";
res.innerHTML = "- test: 'TRUE'<br />";
res.innerHTML += "- match.input: '" + match.input + "'<br />";
res.innerHTML += "- match[0]: '" + match[0] + "'<br />";
res.innerHTML += "- match[1]: '" + match[1] + "'<br />";
res.innerHTML += "- match[2]: '" + match[2] + "'<br />";
res.innerHTML += "- match[3]: '" + match[3] + "'";
}
else {
res.innerHTML = "- test: 'FALSE'";
}
}
</script>
</head>
<body>
<p id="res">results:</p>
<form action="" method="post">
<input type="button" onclick="expressionTest()" value="TEST EXPRESSION" />
</form>
</body>
</html>
Comments
No comments have been made yet.
Please login to leave a comment. Login now