📄 regexp.html
字号:
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Matches the preceding item 0 or more times.</ztabletext></FONT><P><A NAME="1193217"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/bo*/</FONT> matches 'boooo' in "A ghost booooed" and 'b' in "A bird warbled", but nothing in "A goat grunted".</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1193219"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>+</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1193221"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Matches the preceding item 1 or more times. Equivalent to <FONT FACE="courier, couriernew, monospaced size">{1,}</FONT>.</ztabletext></FONT><P><A NAME="1193222"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/a+/</FONT> matches the 'a' in "candy" and all the a's in "caaaaaaandy".</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1193224"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>?</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1193226"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Matches the preceding item 0 or 1 time.</ztabletext></FONT><P><A NAME="1193227"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/e?le?/</FONT> matches the 'el' in "angel" and the 'le' in "angle."</ztabletext></FONT><P><A NAME="1207474"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>If used immediately after any of the quantifiers <FONT FACE="courier, couriernew, monospaced size">*</FONT>, <FONT FACE="courier, couriernew, monospaced size">+</FONT>, <FONT FACE="courier, couriernew, monospaced size">?</FONT>, or <FONT FACE="courier, couriernew, monospaced size">{}</FONT>, makes the quantifier non-greedy (matching the minimum number of times), as opposed to the default, which is greedy (matching the maximum number of times). </ztabletext></FONT><P><A NAME="1207985"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Also used in lookahead assertions, described under (?=)<FONT FACE="courier, couriernew, monospaced size">, </FONT>(?!), and (?:) in this table.</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1193229"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>.</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1193231"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>(The decimal point) matches any single character except the newline character.</ztabletext></FONT><P><A NAME="1193232"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/.n/</FONT> matches 'an' and 'on' in "nay, an apple is on the tree", but not 'nay'.</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1193234"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>(x)</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1193236"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Matches 'x' and remembers the match. These are called capturing parentheses.</ztabletext></FONT><P><A NAME="1193237"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/(foo)/</FONT> matches and remembers 'foo' in "foo bar." The matched substring can be recalled from the resulting array's elements <FONT FACE="courier, couriernew, monospaced size">[1]</FONT>, ..., <FONT FACE="courier, couriernew, monospaced size">[n] </FONT>or from the predefined <FONT FACE="courier, couriernew, monospaced size">RegExp</FONT> object's properties <FONT FACE="courier, couriernew, monospaced size">$1</FONT><I>, ..., </I><FONT FACE="courier, couriernew, monospaced size">$9</FONT>.</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1207782"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>(?:x)</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1207798"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Matches 'x' but does not remember the match. These are called non-capturing parentheses. The matched substring can not be recalled from the resulting array's elements <FONT FACE="courier, couriernew, monospaced size">[1]</FONT>, ..., <FONT FACE="courier, couriernew, monospaced size">[n] </FONT>or from the predefined <FONT FACE="courier, couriernew, monospaced size">RegExp</FONT> object's properties <FONT FACE="courier, couriernew, monospaced size">$1</FONT><I>, ..., </I><FONT FACE="courier, couriernew, monospaced size">$9</FONT>.</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1207829"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>x(?=y)</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1207831"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Matches 'x' only if 'x' is followed by 'y'. For example, <FONT FACE="courier, couriernew, monospaced size">/Jack(?=Sprat)/</FONT> matches 'Jack' only if it is followed by 'Sprat'. /<FONT FACE="courier, couriernew, monospaced size">Jack(?=Sprat|Frost)/</FONT>matches 'Jack' only if it is followed by 'Sprat' or 'Frost'. However, neither 'Sprat' nor 'Frost' is part of the match results.</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1207825"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>x(?!y)</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1207827"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Matches 'x' only if 'x' is not followed by 'y'. For example, <FONT FACE="courier, couriernew, monospaced size">/\d+(?!\.)/</FONT> matches a number only if it is not followed by a decimal point. <br><FONT FACE="courier, couriernew, monospaced size">/\d+(?!\.)/.exec("3.141")</FONT> matches 141 but not 3.141.</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1193239"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>x|y</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1193241"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Matches either 'x' or 'y'.</ztabletext></FONT><P><A NAME="1193242"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/green|red/</FONT> matches 'green' in "green apple" and 'red' in "red apple."</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1193244"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>{n}</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1193246"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Where <FONT FACE="courier, couriernew, monospaced size">n</FONT> is a positive integer. Matches exactly <FONT FACE="courier, couriernew, monospaced size">n</FONT> occurrences of the preceding item.</ztabletext></FONT><P><A NAME="1193247"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/a{2}/</FONT> doesn't match the 'a' in "candy," but it matches all of the a's in "caandy," and the first two a's in "caaandy."</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1193249"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>{n,}</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1193251"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Where <FONT FACE="courier, couriernew, monospaced size">n</FONT> is a positive integer. Matches at least <FONT FACE="courier, couriernew, monospaced size">n</FONT> occurrences of the preceding item.</ztabletext></FONT><P><A NAME="1193252"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/a{2,}</FONT> doesn't match the 'a' in "candy", but matches all of the a's in "caandy" and in "caaaaaaandy."</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1193254"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>{n,m}</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1193256"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Where <FONT FACE="courier, couriernew, monospaced size">n</FONT> and <FONT FACE="courier, couriernew, monospaced size">m</FONT> are positive integers. Matches at least <FONT FACE="courier, couriernew, monospaced size">n</FONT> and at most <FONT FACE="courier, couriernew, monospaced size">m</FONT> occurrences of the preceding item.</ztabletext></FONT><P><A NAME="1193257"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/a{1,3}/</FONT> matches nothing in "cndy", the 'a' in "candy," the first two a's in "caandy," and the first three a's in "caaaaaaandy". Notice that when matching "caaaaaaandy", the match is "aaa", even though the original string had more a's in it.</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1193259"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>[xyz]</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1193261"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>A character set. Matches any one of the enclosed characters. You can specify a range of characters by using a hyphen.</ztabletext></FONT><P><A NAME="1193262"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">[abcd]</FONT> is the same as <FONT FACE="courier, couriernew, monospaced size">[a-c]</FONT>. They match the 'b' in "brisket" and the 'c' in "ache"<FONT FACE="courier, couriernew, monospaced size">.</FONT></ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1193264"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>[^xyz]</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1193266"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>A negated or complemented character set. That is, it matches anything that is not enclosed in the brackets. You can specify a range of characters by using a hyphen.</ztabletext></FONT><P><A NAME="1193267"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">[^abc]</FONT> is the same as <FONT FACE="courier, couriernew, monospaced size">[^a-c]</FONT>. They initially match 'r' in "brisket" and 'h' in "chop."</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1193269"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>[\b]</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1193271"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Matches a backspace. (Not to be confused with <FONT FACE="courier, couriernew, monospaced size">\b</FONT>.)</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1193273"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>\b</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1193275"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Matches a word boundary, such as a space. (Not to be confused with <FONT FACE="courier, couriernew, monospaced size">[\b]</FONT>.)</ztabletext></FONT><P><A NAME="1193276"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/\bn\w/</FONT> matches the 'no' in "noonday";<FONT FACE="courier, couriernew, monospaced size">/\wy\b/</FONT> matches the 'ly' in "possibly yesterday."</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1193278"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>\B</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1193280"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Matches a non-word boundary.</ztabletext></FONT><P><A NAME="1193281"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/\w\Bn/</FONT> matches 'on' in "noonday", and <FONT FACE="courier, couriernew, monospaced size">/y\B\w/</FONT> matches 'ye' in "possibly yesterday."</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1193283"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>\c<I>X</I></zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1193285"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Where <I>X</I> is a letter from A - Z. Matches a control character in a string.</ztabletext></FONT><P><A NAME="1193286"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/\cM/</FONT> matches control-M in a string.</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1193288"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>\d</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1193290"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Matches a digit character. Equivalent to <FONT FACE="courier, couriernew, monospaced size">[0-9]</FONT>.</ztabletext></FONT><P><A NAME="1193291"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/\d/</FONT> or <FONT FACE="courier, couriernew, monospaced size">/[0-9]/</FONT> matches '2' in "B2 is the suite number."</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1193293"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>\D</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1193295"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Matches any non-digit character. Equivalent to <FONT FACE="courier, couriernew, monospaced size">[^0-9]</FONT>.</ztabletext></FONT><P><A NAME="1193296"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>For example, <FONT FACE="courier, couriernew, monospaced size">/\D/</FONT> or <FONT FACE="courier, couriernew, monospaced size">/[^0-9]/</FONT> matches 'B' in "B2 is the suite number."</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1193298"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>\f</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1193300"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Matches a form-feed.</ztabletext></FONT> </TD> </TR> <TR> <TD VALIGN=TOP><A NAME="1193302"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2"><zcodeline>\n</zcodeline></FONT><P> </TD> <TD VALIGN=TOP><P><A NAME="1193304"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><ztabletext>Matches a linefeed.</ztabletext>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -