⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regexp.html

📁 javascript 1.5规范
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<A NAME="1194898"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The following table shows the results for this script:</zparagraph></FONT><P><P><A NAME="1195304"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><BR><P><TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">  <CAPTION></CAPTION><P><FONT FACE=""><B></B></FONT><BR><BR>  <TR BGCOLOR="#CCCCCC" ALIGN=LEFT VALIGN=TOP>    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1194779"> </A><P ALIGN="LEFT"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><ztablehead>Object</ztablehead></B></FONT></TH>    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1194781"> </A><P ALIGN="LEFT"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><ztablehead>Property/Index</ztablehead></B></FONT></TH>    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1194783"> </A><P ALIGN="LEFT"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><ztablehead>Description</ztablehead></B></FONT></TH>    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1194785"> </A><P ALIGN="LEFT"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><ztablehead>Example</ztablehead></B></FONT></TH>  </DIV></TR>  <TR>    <TD VALIGN=TOP COLSPAN=1 ROWSPAN=5><A NAME="1194787"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>myArray</zcodeline></FONT><P></TD>    <TD VALIGN=TOP><A NAME="1194789"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline></zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1194791"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>The contents of <FONT FACE="courier, couriernew, monospaced size">myArray.</FONT></ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1194793"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><FONT FACE="courier, couriernew, monospaced size">["dbBd", "bB", "d"]</FONT></ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><A NAME="1194797"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>index</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1194799"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>The 0-based index of the match in the string.</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1194801"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><FONT FACE="courier, couriernew, monospaced size">1</FONT></ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><A NAME="1194805"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>input</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1194807"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>The original string.</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1194809"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><FONT FACE="courier, couriernew, monospaced size">cdbBdbsbz</FONT></ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><A NAME="1194813"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>[0]</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1194815"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>The last matched characters.</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1194817"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><FONT FACE="courier, couriernew, monospaced size">dbBd</FONT></ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><A NAME="1194821"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>[1], ...[<I>n</I>]</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1194823"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>The parenthesized substring matches, if any. The number of possible parenthesized substrings is unlimited.</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1194825"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><FONT FACE="courier, couriernew, monospaced size">[1] = bB<br>[2] = d</FONT></ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP COLSPAN=1 ROWSPAN=5><A NAME="1194827"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>myRe</zcodeline></FONT><P></TD>    <TD VALIGN=TOP><A NAME="1194829"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>lastIndex</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1194831"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>The index at which to start the next match.</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1194833"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><FONT FACE="courier, couriernew, monospaced size">5</FONT></ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><A NAME="1194837"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>ignoreCase</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1194839"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Indicates if the <FONT FACE="courier, couriernew, monospaced size">"i"</FONT> flag was used to ignore case.</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1194841"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><FONT FACE="courier, couriernew, monospaced size">true</FONT></ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><A NAME="1194845"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>global</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1194847"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Indicates if the <FONT FACE="courier, couriernew, monospaced size">"g"</FONT> flag was used for a global match.</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1194849"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><FONT FACE="courier, couriernew, monospaced size">true</FONT></ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><A NAME="1208547"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>multiline</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1208563"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Indicates if the <FONT FACE="courier, couriernew, monospaced size">"m"</FONT> flag was used for a global match.</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1208551"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>false</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><A NAME="1194853"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>source</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1194855"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>The text of the pattern.</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1194857"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><FONT FACE="courier, couriernew, monospaced size">d(b+)(d)</FONT></ztabletext></FONT>&nbsp;</TD>  </TR></TABLE><P></FONT><P><A NAME="1194899"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>If your regular expression uses the <FONT FACE="courier, couriernew, monospaced size">"g"</FONT> flag, you can use the <FONT FACE="courier, couriernew, monospaced size">exec</FONT> method multiple times to find successive matches in the same string. When you do so, the search starts at the substring of <FONT FACE="courier, couriernew, monospaced size">str</FONT> specified by the regular expression's <FONT FACE="courier, couriernew, monospaced size">lastIndex</FONT> property. For example, assume you have this script:</zparagraph></FONT><P><A NAME="1194900"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>&lt;SCRIPT LANGUAGE="JavaScript1.2"&gt;<br>myRe=/ab*/g;<br>str = "abbcdefabh";<br>myArray = myRe.exec(str);<br>document.writeln("Found " + myArray[0] + <br>&nbsp;&nbsp;&nbsp;". Next match starts at " + myRe.lastIndex)<br>mySecondArray = myRe.exec(str);<br>document.writeln("Found " + mySecondArray[0] + <br>&nbsp;&nbsp;&nbsp;". Next match starts at " + myRe.lastIndex)<br>&lt;/SCRIPT&gt;</zcodeline></FONT><P><A NAME="1194901"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>This script displays the following text:</zparagraph></FONT><P><A NAME="1194902"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Found <FONT FACE="courier, couriernew, monospaced size">abb</FONT>. Next match starts at 3<br>Found ab. Next match starts at 9</zparagraph></FONT><P><BR><A NAME="1194903"> </A><A NAME="Examples"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><zrefheader>Examples</zrefheader></B></FONT><BR><A NAME="1194904"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>In the following example, the user enters a name and the script executes a match against the input. It then cycles through the array to see if other names match the user's name. </zparagraph></FONT><P><A NAME="1194905"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>This script assumes that first names of registered party attendees are preloaded into the array A, perhaps by gathering them from a party database. </zparagraph></FONT><P><A NAME="1194906"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>&lt;HTML&gt;</zcodeline></FONT><P><A NAME="1194907"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>&lt;SCRIPT LANGUAGE="JavaScript1.2"&gt;<br>A = ["Frank", "Emily", "Jane", "Harry", "Nick", "Beth", "Rick", <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Terrence", "Carol", "Ann", "Terry", "Frank", "Alice", "Rick", <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Bill", "Tom", "Fiona", "Jane", "William", "Joan", "Beth"]</zcodeline></FONT><P><A NAME="1194908"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>function lookup() {<br>&nbsp;&nbsp;&nbsp;firstName = /\w+/i();<br>&nbsp;&nbsp;&nbsp;if (!firstName)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.alert (RegExp.input + " isn't a name!");<br>&nbsp;&nbsp;&nbsp;else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (i=0; i&lt;A.length; i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (firstName[0].toLowerCase() == A[i].toLowerCase()) count++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (count ==1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;midstring = " other has ";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;midstring = " others have ";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.alert ("Thanks, " + count + midstring + "the same name!")<br>&nbsp;&nbsp;&nbsp;}<br>}</zcodeline></FONT><P><A NAME="1194909"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>&lt;/SCRIPT&gt;</zcodeline></FONT><P><A NAME="1194910"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>Enter your first name and then press Enter.</zcodeline></FONT><P><A NAME="1194911"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>&lt;FORM&gt; &lt;INPUT TYPE:"TEXT" NAME="FirstName" onChange="lookup(this);"&gt; &lt;/FORM&gt;</zcodeline></FONT><P><A NAME="1194912"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>&lt;/HTML&gt;</zcodeline></FONT><P><BR><P><A NAME="1194562"> </A><A NAME="global"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="4"><B><zrefhead2>global</zrefhead2></B></FONT><P><A NAME="1193669"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Whether or not the <FONT FACE="courier, couriernew, monospaced size">"g"</FONT> flag is used with the regular expression. <BR><P><TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">  <CAPTION></CAPTION><P><FONT FACE=""><B></B></FONT><BR><BR>  <TR>    <TD VALIGN=TOP><P><A NAME="1193655"> </A><FONT FACE="Arial, Helvetica, 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -