HTML and CSS Reference
In-Depth Information
Table 17.8 Metasymbols
Symbol
What It Matches
Character Class
\d
One digit
[0-9]
\D
One nondigit
[^0-9]
\s
One whitespace character (tab, space, newline,
carriage return, formfeed, vertical tab)
\S
One nonspace character
\w
One word character
[A-Za-z0-9_]
\W
One nonword character
[^A-Za-z0-9]
EXAMPLE 17.15
<html>
<head><title>The Digit Meta Symbol</title></head>
<body>
<script type="text/javascript">
1
var reg_expression = /6\d\d/;
2
var textString=prompt("Type a string of text","");
3
var result=reg_expression.test(textString) ;// Returns true
// or false
document.write(result+"<br />");
if (result){
document.write("<b>The regular expression /6\\d\\d/ matched
the string\""+ textString +"\".<br />");
}
else{
alert("No Match!");
}
</script>
</body>
</html>
EXPLANATION
1
The variable is assigned a regular expression containing the number 6, followed
by two single digits. The metasymbol \d represents the character class [0-9].
2
The variable textString is assigned user input; in this example, 126553 was en-
tered.
3
The regular expression test() method will return true because this string, 126553 ,
contains a 6 followed by any two digits. See Figure 17.16.
 
Search WWH ::




Custom Search