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

📄 regexp.html

📁 javascript 1.5规范
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<HTML><HEAD>        <META NAME="keywords" CONTENT="electronic commerce, ecommerce, ebusiness, e-business, e-commerce, enterprise software, net economy, Netscape, Sun Microsystems, Sun-Netscape Alliance, iPlanet, internet software">        <META NAME="description" CONTENT="The Sun-Netscape Alliance, a strategic alliance formed by America Online and Sun Microsystems, Inc., is delivering iPlanet e-commerce software and enterprise solutions that enable companies to compete successfully in the Net Economy">	<META HTTP-EQUIV="Content-Type" content="text/html; charset=ISO-8859-1">	<META NAME="TEMPLATEBASE" CONTENT="Authored in FrameMaker. Converted to HTML in WebWorks Publisher 2000. manual wdt 1.5">	<META NAME="LASTUPDATED" CONTENT="09/28/00 13:15:53">	<TITLE> Core JavaScript Reference 1.5:  </TITLE></HEAD><BODY TEXT="#000000" LINK="#666699" VLINK="#666699" ALINK="#333366" BGCOLOR="#FFFFFF"><MAINCONTENT><NAVIGATIONCONTENT>   <TABLE WIDTH="100%" BORDER="0" CELLSPACING="4">      <TR>         <TD VALIGN="TOP">            <b><a href="packages.html"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Previous</a></FONT>&nbsp;&nbsp;&nbsp;&nbsp;</b><a href="contents.html"><b><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Contents</a></FONT></b>&nbsp;&nbsp;&nbsp;&nbsp;<a href="ix.html"><b><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Index</a></FONT></b>&nbsp;&nbsp;&nbsp;&nbsp;<a href="string.html"><b><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Next</a></FONT></b>&nbsp;&nbsp;&nbsp;&nbsp;         </TD>     </TR>      <TR>         <TD VALIGN="TOP" ALIGN="RIGHT" BGCOLOR="#CCCCCC">            <FONT FACE="Arial, Helvetica, sans-serif" COLOR="#000000" SIZE="2"><B>             Core JavaScript Reference 1.5</B></FONT>         </TD>      </TR>      <TR>   </TABLE>   <BR></NAVIGATIONCONTENT><BOOKCONTENT>   <blockquote><BR><BR>      <BR><BR><P><A NAME="1193136"> </A><A NAME="RegExp"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="5"><B><zrefhead1>RegExp</zrefhead1></B></FONT><P><A NAME="1193138"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>A regular expression object contains the pattern of a regular expression. It has properties and methods for using that regular expression to find and replace matches in strings.</zparagraph></FONT><P><A NAME="1193139"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>In addition to the properties of an individual regular expression object that you create using the <FONT FACE="courier, couriernew, monospaced size">RegExp</FONT> constructor function, the predefined <FONT FACE="courier, couriernew, monospaced size">RegExp</FONT> object has static properties that are set whenever any regular expression is used.<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 COLSPAN=2 ROWSPAN=1><P><A NAME="1193142"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><I>Core object</I></ztabletext></FONT></TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1193146"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext><I>Implemented in</I></ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1193148"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>JavaScript 1.2, NES 3.0</ztabletext></FONT><P><A NAME="1195460"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext></ztabletext></FONT><P><A NAME="1193152"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>JavaScript 1.3: added <A HREF="regexp.html#1194174"  >toSource</A> method.</ztabletext></FONT><P><A NAME="1207367"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext></ztabletext></FONT><P><A NAME="1207371"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>JavaScript 1.5, NES 6.0: added <FONT FACE="courier, couriernew, monospaced size">m</FONT> flag, non-greedy modifier, non-capturing parentheses, lookahead assertions. ECMA 262, Edition 3</ztabletext></FONT>&nbsp;</TD>  </TR></TABLE><P></zparagraph></FONT><P><BR><A NAME="1193153"> </A><A NAME="Created by"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><zrefheader>Created by</zrefheader></B></FONT><BR><A NAME="1193154"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>A literal text format or the <FONT FACE="courier, couriernew, monospaced size">RegExp</FONT> constructor function. </zparagraph></FONT><P><A NAME="1193155"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The literal format is used as follows:</zparagraph></FONT><P><A NAME="1193156"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>/<I>pattern</I>/<I>flags</I></zcodeline></FONT><P><A NAME="1193157"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The constructor function is used as follows:</zparagraph></FONT><P><A NAME="1193158"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>new RegExp("<I>pattern</I>"[, "<I>flags</I>"])</zcodeline></FONT><P><BR><A NAME="1193159"> </A><A NAME="Parameters"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><zrefheader>Parameters</zrefheader></B></FONT><BR><A NAME="1193172"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph><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><A NAME="1193162"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>pattern</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1193164"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>The text of the regular expression.</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><A NAME="1193166"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>flags</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1193168"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>If specified, flags can have any combination of the following values:</ztabletext></FONT><ul><A NAME="1193169"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B>  <li></B><zsmartlist1><FONT FACE="courier, couriernew, monospaced size">g</FONT>: global match</zsmartlist1></FONT><P><A NAME="1193170"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B>  <li></B><zsmartlist1><FONT FACE="courier, couriernew, monospaced size">i</FONT>: ignore case</zsmartlist1></FONT><P><A NAME="1207375"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B>  <li></B><zsmartlist1><FONT FACE="courier, couriernew, monospaced size">m</FONT>: match over multiple lines</zsmartlist1></FONT><P></ul>&nbsp;</TD>  </TR></TABLE><P></zparagraph></FONT><P><A NAME="1193173"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Notice that the parameters to the literal format do not use quotation marks to indicate strings, while the parameters to the constructor function do use quotation marks. So the following expressions create the same regular expression:</zparagraph></FONT><P><A NAME="1193174"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>/ab+c/i<br>new RegExp("ab+c", "i")</zcodeline></FONT><P><BR><A NAME="1193175"> </A><A NAME="Description"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><zrefheader>Description</zrefheader></B></FONT><BR><A NAME="1193176"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When using the constructor function, the normal string escape rules (preceding special characters with \ when included in a string) are necessary. For example, the following are equivalent:</zparagraph></FONT><P><A NAME="1193177"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>re = new&nbsp;RegExp("\\w+")<br>re = /\w+/</zcodeline></FONT><P><A NAME="1193181"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The following table provides a complete list and description of the special characters that can be used in regular expressions.</zparagraph></FONT><P><P><A NAME="1195218"> </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><A NAME="1193188"> </A><A NAME="Special characters in regular expressions. &nbsp;"> </A><ALIGN="LEFT"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><ztablecaption>Table 1.1&#32;&nbsp&nbsp Special characters in regular expressions. &nbsp;</ztablecaption></B></FONT></B></FONT><BR><BR>  <TR BGCOLOR="#CCCCCC" ALIGN=LEFT VALIGN=TOP>    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1193192"> </A><P ALIGN="LEFT"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><ztablehead>Character</ztablehead></B></FONT></TH>    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1193194"> </A><P ALIGN="LEFT"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><B><ztablehead>Meaning</ztablehead></B></FONT></TH>  </DIV></TR>  <TR>    <TD VALIGN=TOP><A NAME="1193196"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>\</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1193198"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For characters that are usually treated literally, indicates that the next character is special and not to be interpreted literally. </ztabletext></FONT><P><A NAME="1193199"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/b/</FONT> matches the character 'b'. By placing a backslash in front of b, that is by using <FONT FACE="courier, couriernew, monospaced size">/\b/</FONT>, the character becomes special to mean match a word boundary.</ztabletext></FONT><P><A NAME="1193200"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>-or-</ztabletext></FONT><P><A NAME="1193201"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For characters that are usually treated specially, indicates that the next character is not special and should be interpreted literally. </ztabletext></FONT><P><A NAME="1193202"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">*</FONT> is a special character that means 0 or more occurrences of the preceding character should be matched; for example, <FONT FACE="courier, couriernew, monospaced size">/a*/</FONT> means match 0 or more a's<FONT FACE="courier, couriernew, monospaced size">.</FONT> To match <FONT FACE="courier, couriernew, monospaced size">*</FONT> literally, precede the it with a backslash; for example, <FONT FACE="courier, couriernew, monospaced size">/a\*/</FONT> matches 'a*'.</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><A NAME="1193204"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>^</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1193206"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Matches beginning of input. If the multiline flag is set to true, also matches immediately after a line break character.</ztabletext></FONT><P><A NAME="1193207"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/^A/</FONT> does not match the 'A' in "an A", but does match the first 'A' in "An A."</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><A NAME="1193209"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>$</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1208350"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Matches end of input. If the multiline flag is set to true, also matches immediately before a line break character.</ztabletext></FONT><P><A NAME="1193212"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/t$/</FONT> does not match the 't' in "eater", but does match it in "eat".</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><A NAME="1193214"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>*</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1193216"> </A>

⌨️ 快捷键说明

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