<html>
<link rel="stylesheet" href="josh.css">
<body bgcolor="#FFFFFF">

		<div id="Description">
			<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
				<tr><td valign="top" class="name">regular expression</td><td valign="top" nowrap class="compatibility">NN <span class="emphasis">4</span> IE <span class="emphasis">4</span> ECMA <span class="emphasis">3</span>&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" nowrap class="usage"><p class="literal"></p>
					</td><td valign="top" nowrap class="requirements">&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="description">
						<p>A regular expression object is an instance of the
<span class="literal">RegExp</span> object. Each regular expression object
consists of a pattern that is used to locate matches within a string.
Patterns for a regular expression can be simple strings or
significantly more powerful expressions that use a notation that is
essentially a language unto itself. The implementation of regular
expressions in JavaScript 1.2 is very similar to the way they are
implemented in Perl. You can read more about these concepts in books
covering JavaScript 1.2 or later.
</p>
							</td>
						</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
						<tr>
							<td colspan="2"><p>			To create a regular expression object, surround the pattern with
forward slashes, and assign the whole expression to a variable. For
example, the following statement creates a regular expression with a
pattern that is a simple word:
</p>
<span class="PROGRAMLISTING"><pre>var re = /greet/;</pre></span>
							</td>
						</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
						<tr>
							<td colspan="2"><p>			The <span class="literal">re</span> variable can then be used as a parameter in
a variety of methods that search for the pattern within some string
(you may also use an expression directly as a method parameter,
rather than assigning it to a variable).
</p>
							</td>
						</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
						<tr>
							<td colspan="2"><p>			Regular expression notation also consists of a number of
metacharacters that stand in for sometimes complex ideas, such as the
boundary on either side of a word, any numeral, or one or more
characters. For example, to search for the pattern of characters
shown above but only when the pattern is a word (and not part of a
word such as greetings), the regular expression notation uses the
metacharacters to indicate that the pattern includes word boundaries
on both sides of the pattern:
</p>
<span class="PROGRAMLISTING"><pre>var re = /\bgreet\b/;</pre></span>
							</td>
						</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
						<tr>
							<td colspan="2"><p>			The following table shows a summary of the regular expression
notation used in JavaScript 1.2.
</p>
							</td>
						</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
						<tr>
							<td colspan="2"><p>			When you create a regular expression, you may optionally wire the
expression to work globally (as you probably do if the regular
expression is doing a search-and-replace operation with a method, and
your goal is a "replace all"
result) and to ignore case in its matches. The modifiers that turn on
these switches are the letters <span class="literal">g</span> and
<span class="literal">i</span>. They may be used by themselves or together as
<span class="literal">gi</span>.
</p>
							</td>
						</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
						<tr>
							<td colspan="2"><p>			Once you have established a pattern with the regular expression
notation, all the action takes place in the regular expression object
methods and the <span class="literal">String</span> object methods that accept
regular expression parameters.
</p>
							</td>
						</tr>
						<tr>
							<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
						</tr>
						<tr>
							<td>
								<table border="1"><tbody><tr><th>Character</th><th>Matches</th><th>Example</th></tr>
										<tr><td> \b</td><td>Word boundary</td><td><span class="literal">/\bto/</span> matches
"tomorrow"<span class="literal">/to\b/</span>
matches "Soweto"
</td>
										</tr>
										<tr><td> \B</td><td>Word nonboundary</td><td><span class="literal">/\Bto/</span> matches
"stool" and
"Soweto"<span class="literal">/to\B/</span>
matches "stool" and
"tomorrow"
</td>
										</tr>
										<tr><td> \d</td><td>Numeral 0 through 9</td><td><span class="literal">/\d\d/</span> matches
"42"
</td>
										</tr>
										<tr><td> \D</td><td>Nonnumeral</td><td><span class="literal">/\D\D/</span> matches
"to"
</td>
										</tr>
										<tr><td> \s</td><td>Single whitespace</td><td><span class="literal">/under\sdog/</span> matches "under
dog"
</td>
										</tr>
										<tr><td> \S</td><td>Single nonwhitespace</td><td><span class="literal">/under\Sdog/</span> matches
"under-dog"
</td>
										</tr>
										<tr><td> \w</td><td>Letter, numeral, or underscore</td><td><span class="literal">/1\w/</span> matches
"1A"
</td>
										</tr>
										<tr><td> \W</td><td>Not a letter, numeral, or underscore</td><td><span class="literal">/1\W/</span> matches
"1%"
</td>
										</tr>
										<tr><td> .</td><td>Any character except a newline</td><td><span class="literal">/../</span> matches "Z3"</td>
										</tr>
										<tr><td> [...]</td><td>Any one of the character set in brackets</td><td><span class="literal">/J[aeiou]y/</span> matches
"Joy"
</td>
										</tr>
										<tr><td> [^...]</td><td>Negated character set</td><td><span class="literal">/J[^eiou]y/</span> matches
"Jay"
</td>
										</tr>
										<tr><td> *</td><td>Zero or more times</td><td><span class="literal">/\d*/</span> matches "", "5", or "444"
</td>
										</tr>
										<tr><td> ?</td><td>Zero or one time</td><td><span class="literal">/\d?/</span> matches "" or "5"
</td>
										</tr>
										<tr><td> +</td><td>One or more times</td><td><span class="literal">/\d+/</span> matches
"5" or
"444"
</td>
										</tr>
										<tr><td> {n}</td><td>Exactly n times</td><td><span class="literal">/\d{2}/</span> matches
"55"
</td>
										</tr>
										<tr><td> {n,}</td><td>n or more times</td><td><span class="literal">/\d{2,}/</span> matches
"555"
</td>
										</tr>
										<tr><td> {n,m}</td><td>At least n, at most m times</td><td><span class="literal">/\d{2,4}/</span> matches
"5555"
</td>
										</tr>
										<tr><td> ^</td><td>At beginning of a string or line</td><td><span class="literal">/^Sally/</span> matches "Sally
says..."
</td>
										</tr>
										<tr><td> $</td><td>At end of a string or line</td><td><span class="literal">/Sally.$/</span> matches "Hi,
Sally."
</td>
										</tr>
									</tbody></table>
												</td>
</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="properties"><span class="title">Properties</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td>
						<table border="1"><tbody><tr><td><span class="literal">constructor</span></td><td> <span class="literal">global</span></td><td> <span class="literal">ignoreCase</span></td><td> <span class="literal">lastIndex</span></td><td> <span class="literal">source</span></td>
								</tr>
							</tbody></table>
					</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="methods"><span class="title">Methods</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td>
						<table border="1"><tbody><tr><td><span class="literal">compile( )</span></td><td> <span class="literal">exec( )</span></td><td> <span class="literal">test( )</span></td>
								</tr>
							</tbody></table>
					</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="creatingaregularexpressionobject"><span class="title">Creating a regular expression Object</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td><span class="programlisting"><pre>var regExpressionObj = /pattern/ [g | i | gi];
var regExpressionObj = new RegExp(["pattern", ["g" | "i" | "gi"]]);</pre>
						</span></td>
				</tr>
			</table>
		</div><div id="constructor">
			<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
				<tr><td valign="top" class="name">constructor</td><td valign="top" nowrap class="compatibility">NN <span class="emphasis">4</span> IE <span class="emphasis">4</span> ECMA <span class="emphasis">3</span>&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" nowrap class="usage"><p class="literal"></p>
					</td><td valign="top" nowrap class="requirements">Read/Write&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="description">
						<p>See this property for the <span class="literal">Array</span> object.</p>
												</td>
</tr>
			</table>
		</div><div id="global, ignoreCase">
			<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
				<tr><td valign="top" class="name">global, ignoreCase</td><td valign="top" nowrap class="compatibility">NN <span class="emphasis">4</span> IE <span class="emphasis">5(Mac)/5.5(Win)</span> ECMA <span class="emphasis">3</span>&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" nowrap class="usage"><p class="literal"></p>
					</td><td valign="top" nowrap class="requirements">Read-only&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="description">
						<p>Returns Boolean <span class="literal">true</span> if the regular expression
object instance had the <span class="literal">g</span> or <span class="literal">i</span>
modifiers (respectively) set when it was created. If a regular
expression object has both modifiers set (<span class="literal">gi</span>), you
must still test for each property individually.
</p>
												</td>
</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="example"><span class="title">Example</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td><span class="programlisting"><pre>if (myRE.global &amp;&amp; myRE.ignoreCase) {
    ...
}</pre>
						</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="value"><span class="title">Value</span></td>
				</tr>
				<tr>
					<td colspan="2"><p>			Boolean value: <span class="literal">true</span> | <span class="literal">false</span>.</p>
					</td>
				</tr>
			</table>
		</div><div id="lastIndex">
			<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
				<tr><td valign="top" class="name">lastIndex</td><td valign="top" nowrap class="compatibility">NN <span class="emphasis">4</span> IE <span class="emphasis">4</span> ECMA <span class="emphasis">3</span>&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" nowrap class="usage"><p class="literal"></p>
					</td><td valign="top" nowrap class="requirements">Read/Write&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="description">
						<p>This is the zero-based index value of the character within the string
where the next search for the pattern begins. In a new search, the
value is zero. You can also set the value manually if you wish to
start at a different location or skip some characters.
</p>
												</td>
</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="example"><span class="title">Example</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td><span class="programlisting"><pre>myRE.lastIndex = 30;</pre>
						</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="value"><span class="title">Value</span></td>
				</tr>
				<tr>
					<td colspan="2"><p>			Integer.</p>
					</td>
				</tr>
			</table>
		</div><div id="source">
			<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
				<tr><td valign="top" class="name">source</td><td valign="top" nowrap class="compatibility">NN <span class="emphasis">4</span> IE <span class="emphasis">4</span> ECMA <span class="emphasis">3</span>&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" nowrap class="usage"><p class="literal"></p>
					</td><td valign="top" nowrap class="requirements">Read-only&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="description">
						<p>Returns a string version of the characters used to create the regular
expression. The value does not include the forward slash delimiters
that surround the expression.
</p>
												</td>
</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="example"><span class="title">Example</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td><span class="programlisting"><pre>var myREasString = myRE.source;</pre>
						</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="value"><span class="title">Value</span></td>
				</tr>
				<tr>
					<td colspan="2"><p>			String.</p>
					</td>
				</tr>
			</table>
		</div><div id="compile( )">
			<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
				<tr><td valign="top" class="name">compile( )</td><td valign="top" nowrap class="compatibility">NN <span class="emphasis">4</span> IE <span class="emphasis">4</span> ECMA <span class="emphasis">n/a</span>&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" nowrap class="usage"><p class="literal">compile("<span class="replaceable">pattern</span>"[, "g" | "i" | "gi"])</p>
					</td><td valign="top" nowrap class="requirements">&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="description">
						<p>Compiles a regular expression pattern into a genuine regular
expression object. This method is used primarily to recompile a
regular expression with a pattern that may change during the
execution of a script.
</p>
												</td>
</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="parameters"><span class="title">Parameters</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td>
						<ul><li><span class="literal"></span>Any regular expression pattern as a quoted string. Modifiers for
global, ignore case, or both must be supplied as a separate quoted
parameter.
</li></ul>
					</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="returnedvalue"><span class="title">Returned Value</span></td>
				</tr>
				<tr>
					<td colspan="2"><p>			Reference to a regular expression instance.</p>
					</td>
				</tr>
			</table>
		</div><div id="exec( )">
			<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
				<tr><td valign="top" class="name">exec( )</td><td valign="top" nowrap class="compatibility">NN <span class="emphasis">4</span> IE <span class="emphasis">4</span> ECMA <span class="emphasis">3</span>&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" nowrap class="usage"><p class="literal">exec(<span class="replaceable">string</span>)</p>					</td><td valign="top" nowrap class="requirements">&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="description">
						<p>Performs a search through the string passed as a parameter for the
current regular expression pattern. A typical sequence follows the
format:</p>
<span class="PROGRAMLISTING"><pre>var myRE = /somePattern/;
var resultArray = myRE.exec(&quot;someString&quot;);</pre></span>
						</td>
						</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
						<tr>
							<td colspan="2"><p>			Properties of both the static <span class="literal">RegExp</span> and regular
expression instance (<span class="literal">myRE</span> in the example) objects
are updated with information about the results of the search. In
addition, the <span class="literal">exec( )</span> method returns an array of
data, much of it similar to <span class="literal">RegExp</span> object
properties. The returned array includes the following properties:
</p>
<dl>
<dt><span class="LITERAL">index</span></dt>
<dd>
<p>Zero-based index of starting character in the string that matches the
pattern
</p>
</dd>


<dt><span class="LITERAL">input</span></dt>
<dd>
<p>The original string being searched</p>
</dd>


<dt><span class="LITERAL">[0]</span></dt>
<dd>
<p>String of the characters matching the pattern</p>
</dd>


<dt><span class="LITERAL">[1]...[n]</span></dt>
<dd>
<p>Strings of the results of the parenthesized component matches</p>
</dd>

</dl>							</td>
						</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
						<tr>
							<td colspan="2"><p>			You can stow away the results of the <span class="literal">exec( )</span>
method in a variable, whereas the <span class="literal">RegExp</span> property
values change with the next regular expression operation. If the
regular expression is set for global searching, a subsequent call to
<span class="literal">myRE.exec("</span><span class="replaceable">someString</span><span class="literal">")</span>
continues the search from the position of the previous match.
</p>							</td>
						</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
						<tr>
							<td colspan="2"><p>			If no match is found for a given call to <span class="literal">exec( )</span>,
it returns <span class="literal">null</span>.
</p>							</td>
						</tr>
						
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="parameters"><span class="title">Parameters</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td>
						<ul><li><span class="literal"></span>The string to be searched.</li></ul>					</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="returnedvalue"><span class="title">Returned Value</span></td>
				</tr>
				<tr>
					<td colspan="2"><p>			An array of match information if successful; <span class="literal">null</span>
if there is no match.
</p>					</td>
				</tr>
			</table>
		</div><div id="test( )">
			<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
				<tr><td valign="top" class="name">test( )</td><td valign="top" nowrap class="compatibility">NN <span class="emphasis">4</span> IE <span class="emphasis">4</span> ECMA <span class="emphasis">3</span>&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" nowrap class="usage"><p class="literal">test(<span class="replaceable">string</span>)</p>
					</td><td valign="top" nowrap class="requirements">&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="description">
						<p>Returns Boolean <span class="literal">true</span> if there is a match of the
regular expression anywhere in the string passed as a parameter,
<span class="literal">false</span> if not. No additional information is
available about the results of the search. This is the fastest way to
find out if a string contains a match for a pattern.
</p>
												</td>
</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="parameters"><span class="title">Parameters</span></td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td>
						<ul><li><span class="literal"></span>The string to be searched. </li></ul>
					</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" class="returnedvalue"><span class="title">Returned Value</span></td>
				</tr>
				<tr>
					<td colspan="2"><p>			Boolean value: <span class="literal">true</span> | <span class="literal">false</span>.</p>
					</td>
				</tr>
			</table>
		</div>

</body>
</html>