好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

正则入门连载!(献给不及格的程序员们)

正则表达式  
通过与大多数读者已经熟悉的一些概念进行比较,说明正则表达式的概念。

本篇内容全部来是微软公司文档,对此表示感谢,像那些为此而工作过的人们.

除非您以前使用过正则表达式,否则您可能不熟悉此术语。但是,毫无疑问,您已经使用过不涉及脚本的某些正则表达式概念。

例如,您很可能使用 ? 和 * 通配符来查找硬盘上的文件。? 通配符匹配文件名中的单个字符,而 * 通配符匹配零个或多个字符。像 data?.dat 这样的模式将查找下列文件:

data1.dat
data2.dat
datax.dat
dataN.dat
使用 * 字符代替 ? 字符扩大了找到的文件的数量。data*.dat 匹配下列所有文件:

data.dat
data1.dat
data2.dat
data12.dat
datax.da
dataXYZ.dat
尽管这种搜索方法很有用,但它还是有限的。? 和 * 通配符的能力引入了正则表达式所依赖的概念,但正则表达式功能更强大,而且更加灵活。
正则表达式的用途  
通过实例说明正则表达式如何扩展常规搜索条件。

典型的搜索和替换操作要求您提供与预期的搜索结果匹配的确切文本。虽然这种技术对于对静态文本执行简单搜索和替换任务可能已经足够了,但它缺乏灵活性,若采用这种方法搜索动态文本,即使不是不可能,至少也会变得很困难。

通过使用正则表达式,可以: 

测试字符串内的模式。 
例如,可以测试输入字符串,以查看字符串内是否出现电话号码模式或信用卡号码模式。这称为数据验证。 

替换文本。 
可以使用正则表达式来识别文档中的特定文本,完全删除该文本或者用其他文本替换它。 

基于模式匹配从字符串中提取子字符串。 
可以查找文档内或输入域内特定的文本。 

例如,您可能需要搜索整个 Web 站点,删除过时的材料,以及替换某些 HTML 格式标记。在这种情况下,可以使用正则表达式来确定在每个文件中是否出现该材料或该 HTML 格式标记。此过程将受影响的文件列表缩小到包含需要删除或更改的材料的那些文件。然后可以使用正则表达式来删除过时的材料。最后,可以使用正则表达式来搜索和替换标记。

正则表达式在 JScript 或 C 等语言中也很有用,这些语言的字符串处理能力还不为人们所知。

正则表达式语法  
说明构成正则表达式的字符、构成元字符的字符以及元字符的行为。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <HTML xmlns:MSHelp="http://msdn.microsoft.com/mshelp" DIR="LTR"> <style type="text/css"> /* VERSION 9345 Designed for IE5.x. Optimal in IE 6.x CSS for use with Developer Tools Documentation Localizable definitions: font families font sizes */ /* -------------------------------------------------- MAIN TOPIC STYLES -------------------------------------------------- */ div.saveHistory { behavior:url(#default#savehistory); text-decoration: underline } body /* This body tag requires the use of one of the sets of banner and/or text div ids */ { margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; background: #ffffff; color: #000000; font-family: 瀹嬩綋, Verdana, Arial, Helvetica, sans-serif; font-size: 75%; width: 100%; } div#scrollyes /* Allows topic to scroll with correct margins. Cannot be used with running head banner */ { /* Must immediately follow <body>. */ padding: 2px 15px 2px 22px; width: 100%; } div#nsbanner /* Creates Nonscrolling banner region */ { position: relative; left: 0px; padding: 0px 0px 0px 0px; border-bottom: 1px solid #999999; } div#nstext /* Creates the scrolling text area for Nonscrolling region topic */ { padding: 5px 10px 0px 22px; } div#scrbanner /* Creates the running head bar in a full-scroll topic */ { /* Allows topic to scroll. */ margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; border-bottom: 1px solid #999999; } div#scrtext /* Creates the text area in a full-scroll topic */ { /* Allows topic to scroll. */ /* width: 100%; /* Forces tables to have correct right margin */*/ padding: 0px 10px 0px 22px; } div#bannerrow1 /* provides full-width color to top row in running head (requires script) */ { background-color: #99ccff; } div#titlerow /* provides non-scroll topic title area (requires script) */ { width: 100%; /* Forces tables to have correct right margin */ padding: 0px 10px 0px 22px; background-color: #99ccff; } /* -------------------------------------------------- HEADING STYLES -------------------------------------------------- */ h1, h2, h3, h4 { font-family: 瀹嬩綋, Verdana, Arial, Helvetica, sans-serif; margin-bottom: .4em; margin-top: 1em; font-weight: bold; } h1 { font-size: 120%; margin-top: 0em; } div#scrollyes h1 /* Changes font size for full-scrolling topic */ { font-size: 150%; } h2 { font-size: 120%; } h3 { font-size: 115%; } h4 { font-size: 100%; } .dtH1, .dtH2, .dtH3, .dtH4 { margin-left: -18px; } div#titlerow h1 { margin-bottom: .2em } /* -------------------------------------------------- TEXT STYLES -------------------------------------------------- */ p { margin: .5em 0em .5em 0em; } blockquote.dtBlock { margin: .5em 1.5em .5em 1.5em; } div#dtHoverText { color: #000066; } .normal { margin: .5em 0em .5em 0em; } .fineprint { font-size: 110%; /* 90% of 70% */ } .indent { margin: .5em 1.5em .5em 1.5em; } .topicstatus /* Topic Status Boilerplate class */ { display: block; color: red; } /* -------------------------------------------------- LABEL STYLES -------------------------------------------------- */ p.label { margin-top: 1em; } p.labelproc { margin-top: 1em; color: #000066; } /* -------------------------------------------------- GRAPHIC STYLES -------------------------------------------------- */ img { border: none; } /* -------------------------------------------------- LIST STYLES -------------------------------------------------- */ ol, ul { margin: .5em 0em 0em 2em; } li { margin-bottom: .5em; } ul p, ol p, dl p { margin-left: 0em; } ul p.label, ol p.label { margin-top: .5em; } /* -------------------------------------------------- DEFINITION LIST STYLES -------------------------------------------------- */ dl { margin-top: 0em; padding-left: 1px; /* Prevents italic-letter descenders from being cut off */ } dd { margin-bottom: 0em; margin-left: 1.5em; } dt { margin-top: .5em; } /* -------------------------------------------------- CODE, SYNTAX, and REFTIP STYLES -------------------------------------------------- */ pre { margin-top: .5em; margin-bottom: .5em; } pre, code, .code { font: 100% 瀹嬩綋, Courier New, Monospace, Courier;/* This is 100% of 70% */ color: #000066; } pre b, code b { letter-spacing: .1em; /* opens kerning on bold in Syntax/Code */ } pre.syntax { font: 100% Courier New, 瀹嬩綋, Monospace, Courier;/* This is 100% of 70% */ background: #cccccc; padding: 4px 8px; cursor: text; margin-top: 1em; margin-bottom: 1em; color: #000000; border-width: 1px; border-style: solid; border-color: #999999; } /* -------------------------------------------------- LINK STYLES -------------------------------------------------- */ a:link { color: #0000ff; } a:visited { color: #0000ff; } a:hover { color: #3366ff; } /* --------------------------- MSHelp\:link - Help HxLinks --------------------------- */ MSHelp\:link { text-decoration: underline; color: #0000ff; hoverColor: #3366ff; filterString: ; } A.HxLinkTable /* MSHelp\:link - Table disambiguation elements */ { } /* --------------------------- MSHelp\:ktable - Help links --------------------------- */ MSHelp\:ktable { disambiguator: span; separator: &nbsp|&#32; prefix: |&#32; postfix: &nbsp; filterString: ; } div.HxLinkTable { width: auto; /* Forces tables to have correct right margins and top spacing */ margin-top: -.4em; visibility: visible; } ol div.HxLinkTable, ul div.HxLinkTable { margin-top: 0em; /* Forces tables to have correct right margins and top spacing */ } table.HxLinkTable /* Keep in sync with general table settings below */ { width: auto; margin-top: 1.5em; margin-bottom: .3em; margin-left: -1em; border-width: 1px 1px 0px 0px; border-style: solid; border-color: #999999; background-color: #999999; font-size: 100%; /* Text in Table is same size as text outside table */ behavior:url(hxlinktable.htc); /* Attach the behavior to link elements. */ } table.HxLinkTable th, table.HxLinkTable td /* Keep in sync with general table settings below */ { border-style: solid; /* Creates the cell border and color */ border-width: 0px 0px 1px 1px; border-style: solid; border-color: #999999; padding: 4px 6px; text-align: left; } table.HxLinkTable th /* Keep in sync with general table settings below */ { background: #cccccc; /* Creates the shaded table header row */ vertical-align: bottom; } table.HxLinkTable td /* Keep in sync with general table settings below */ { background: #ffffff; vertical-align: top; } /* -------------------------------------------------- TABLE STYLES -------------------------------------------------- */ div.tablediv { width: 100%; /* Forces tables to have correct right margins and top spacing */ margin-top: -.4em; } ol div.tablediv, ul div.tablediv, ol div.HxLinkTable, ul div.HxLinkTable { margin-top: 0em; /* Forces tables to have correct right margins and top spacing */ } table.dtTABLE { width: 100%; /* Forces tables to have correct right margin */ margin-top: .6em; margin-bottom: .3em; border-width: 1px 1px 0px 0px; border-style: solid; border-color: #999999; background-color: #999999; font-size: 100%; /* Text in Table is same size as text outside table */ } table.dtTABLE th, table.dtTABLE td { border-style: solid; /* Creates the cell border and color */ border-width: 0px 0px 1px 1px; border-style: solid; border-color: #999999; padding: 4px 6px; text-align: left; } table.dtTABLE th { background: #cccccc; /* Creates the shaded table header row */ vertical-align: bottom; } table.dtTABLE td { background: #ffffff; vertical-align: top; } /* -------------------------------------------------- ISSUE REPORTING AND MISC LINKS TOPIC FOOTER -------------------------------------------------- */ div.footer { } div.footer hr { color: #999999; height: 1px; } /* -------------------------------------------------- STYLES FOR RUNNING HEADS -------------------------------------------------- */ table.bannerparthead, table.bannertitle /* General values for the Running Head tables */ { position: relative; left: 0px; top: 0px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px; width: 100%; height: 21px; border-collapse: collapse; border-style: solid; border-width: 0px; background-color: #99ccff; font-size: 100%; } table.bannerparthead td /* General Values for cells in the top row of running head */ { margin: 0px 0px 0px 0px; padding: 2px 0px 0px 4px; vertical-align: middle; /*border-width: 0px 0px 1px 0px; */ border-width: 0px border-style: solid; border-color: #999999; background: transparent; /* font-style: normal; */ font-weight: normal; } table.bannerparthead td.product /* Values for top right cell in running head */ { /* Allows for a second text block in the running head */ text-align: right; padding: 2px 5px 0px 5px; } table.bannertitle td /* General Values for cells in the bottom row of running head */ { margin: 0px 0px 0px 0px; padding: 0px 0px 0px 3px; vertical-align: middle; border-width: 0px 0px 1px 0px; border-style: solid; border-color: #999999; background: transparent; font-weight: bold; } td.button1 /* Values for button cells */ { width: 14px; cursor: hand; } /* ================================================= STYLES REQUIRED BY THE SCRIPT */ /* -------------------------------------------------- SAMPLE VIEWER -------------------------------------------------- */ div#smpMgrCell { display:none; } table.SampMgr { margin: 0px 0px 0px -22px; } table.SampMgr td { padding-left: 22px; } /* -------------------------------------------------- RUNNING HEAD BAR POPUP STYLES: See Also, Requirements, MultiLang Filtering -------------------------------------------------- */ div.sapop, div.langMenu /* See Also & Requirements popups */ { position: absolute; left: 0px; z-index: 1; width: 50%; padding: 0px 8px 5px 26px; visibility: hidden; border: 1px solid #999999; /* Same as all other border colors */ background: #ffffcc; } div.langMenu /* MultiLang Filter popup */ { padding: 10px 10px 10px 10px; } div.langMenu ul { list-style-type: none; padding-left: 5px; margin-left: 0px; } .lang, .ilang /* controls the multilang tag styles */ { color: #333333; font-family: Verdana, Arial, 瀹嬩綋, Helvetica, sans-serif; font-size: 80%; font-weight: normal; font-style: normal; } h1 .lang, h1 .ilang { font-size: 80%; } div.filtered { margin-top: .6em; margin-bottom: .6em; margin-left: -7px; padding: 0px 0px 0px 6px; border-left: 1px solid #999999; background: #ffffff; } div.filtered h1, div.filtered h2, div.filtered h3, div.filtered h4 { margin-left: -22px; } div.filtered span.lang { position: relative; left: 0px; } /* -------------------------------------------------- PARAMETER POPUP STYLES -------------------------------------------------- */ div.reftip /* Defines the RefTip popup in Syntax */ { position: absolute; z-index: 1; visibility: hidden; border: 1px solid #999999; background: #ffffcc; /* padding: 0px 0px 0px 0px; */ } div.reftip dl /* Sets margin around the text within the popup */ { margin: 3px 8px 8px 8px; } a.synParam /* parameter popup links */ { color: #0000ff; /* Must match the a:link style color */ text-decoration: underline; } a.synParam:visited /* ensures parameter popup links are always the unvisited color */ { color: #0000ff; /* Must match the a:link style color */ text-decoration: underline; } a.synParam:hover /* parameter popup links */ { color: #3366ff; /* Must match the a:hover style color */ text-decoration: underline; font-style: italic; } /* -------------------------------------------------- EXPAND-COLLAPSE STYLES -------------------------------------------------- */ div.expandBody { margin: .5em 0em 0em 1.4em; display:none; } a.expandLink1 { font-size: 115%; } a#ExPand { color: #3366ff; font-weight: bold; text-decoration: none; } a#ExPandAll { color: #3366ff; font-weight: bold; text-decoration: none; } /* -------------------------------------------------- GLOSSARY POPUP STYLES Not used by Visual Studio .NET -------------------------------------------------- */ /* COMMENT OUT GLOSSARY SECTION /*div#popUpWindow { Controlled by the script in the variable L_PopUpBoxStyle_Style }*/ a.glosslink:link { color: #000000; } a.glosslink:visited { color: #000000; } a.glosslink:hover { color: #000000; font-style: italic; } div#popUpWindow h5 /* Controls the style of the Term in Glossary Popups */ { margin: 5px 5px 5px 5px; color: #000000; } div#popUpWindow p /* Controls the style of the Text in Glossary Popups */ { margin: 5px 5px 5px 5px; color: #000000; } p.GLOSSARY_TEXT { } div#popUpWindow a /* Controls the style of the Links in Glossary Popups */ { } */ /* END COMMENT OUT OF GLOSSARY SECTION */ /* END STYLES REQUIRED BY THE SCRIPT ================================================== */ </style> <HEAD> <META HTTP-EQUIV="Content-Type" Content="text/html; charset=gb2312"> <TITLE>正则表达式语法</TITLE> <xml> <MSHelp:TOCTitle <HR><!--Feedback Link--> <p><A HREF="JavaScript:sendfeedback('CHS _731801', 'VSDOCS@MICROSOFT.COM')">将文档反馈发送给 Microsoft</A></p><!--Copyright--> <p><MSHelp:link keywords="vxmscCopyright" TABINDEX="0">&copy; 2002 Microsoft Corporation。保留所有权利。</MSHelp:link></p></div> <!--Closes the footer div--> </div> <!--closes the topic content div--> <!--FOOTER_END--> </BODY> </HTML>


生成正则表达式  
描述正则表达式的组件以及组件和分隔符之间的关系。 

正则表达式的结构与算术表达式的结构类似。即,各种元字符和运算符可以将小的表达式组合起来,创建大的表达式。

通过在一对分隔符之间放置表达式模式的各种组件,就可以构建正则表达式。对于 JScript,分隔符是正斜杠 (/) 字符。例如:

/expression/
在上面的示例中,正则表达式模式 (expression) 存储在 RegExp 对象的 Pattern 属性中。

正则表达式的组件可以是单个字符、字符集、字符的范围、在几个字符之间选择或者所有这些组件的任何组合。

优先级顺序
说明如何计算正则表达式以及正则表达式的序列和语法对结果有何影响。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <HTML xmlns:MSHelp="http://msdn.microsoft.com/mshelp" DIR="LTR"> <style type="text/css"> /* VERSION 9345 Designed for IE5.x. Optimal in IE 6.x CSS for use with Developer Tools Documentation Localizable definitions: font families font sizes */ /* -------------------------------------------------- MAIN TOPIC STYLES -------------------------------------------------- */ div.saveHistory { behavior:url(#default#savehistory); text-decoration: underline } body /* This body tag requires the use of one of the sets of banner and/or text div ids */ { margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; background: #ffffff; color: #000000; font-family: 瀹嬩綋, Verdana, Arial, Helvetica, sans-serif; font-size: 75%; width: 100%; } div#scrollyes /* Allows topic to scroll with correct margins. Cannot be used with running head banner */ { /* Must immediately follow <body>. */ padding: 2px 15px 2px 22px; width: 100%; } div#nsbanner /* Creates Nonscrolling banner region */ { position: relative; left: 0px; padding: 0px 0px 0px 0px; border-bottom: 1px solid #999999; } div#nstext /* Creates the scrolling text area for Nonscrolling region topic */ { padding: 5px 10px 0px 22px; } div#scrbanner /* Creates the running head bar in a full-scroll topic */ { /* Allows topic to scroll. */ margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; border-bottom: 1px solid #999999; } div#scrtext /* Creates the text area in a full-scroll topic */ { /* Allows topic to scroll. */ /* width: 100%; /* Forces tables to have correct right margin */*/ padding: 0px 10px 0px 22px; } div#bannerrow1 /* provides full-width color to top row in running head (requires script) */ { background-color: #99ccff; } div#titlerow /* provides non-scroll topic title area (requires script) */ { width: 100%; /* Forces tables to have correct right margin */ padding: 0px 10px 0px 22px; background-color: #99ccff; } /* -------------------------------------------------- HEADING STYLES -------------------------------------------------- */ h1, h2, h3, h4 { font-family: 瀹嬩綋, Verdana, Arial, Helvetica, sans-serif; margin-bottom: .4em; margin-top: 1em; font-weight: bold; } h1 { font-size: 120%; margin-top: 0em; } div#scrollyes h1 /* Changes font size for full-scrolling topic */ { font-size: 150%; } h2 { font-size: 120%; } h3 { font-size: 115%; } h4 { font-size: 100%; } .dtH1, .dtH2, .dtH3, .dtH4 { margin-left: -18px; } div#titlerow h1 { margin-bottom: .2em } /* -------------------------------------------------- TEXT STYLES -------------------------------------------------- */ p { margin: .5em 0em .5em 0em; } blockquote.dtBlock { margin: .5em 1.5em .5em 1.5em; } div#dtHoverText { color: #000066; } .normal { margin: .5em 0em .5em 0em; } .fineprint { font-size: 110%; /* 90% of 70% */ } .indent { margin: .5em 1.5em .5em 1.5em; } .topicstatus /* Topic Status Boilerplate class */ { display: block; color: red; } /* -------------------------------------------------- LABEL STYLES -------------------------------------------------- */ p.label { margin-top: 1em; } p.labelproc { margin-top: 1em; color: #000066; } /* -------------------------------------------------- GRAPHIC STYLES -------------------------------------------------- */ img { border: none; } /* -------------------------------------------------- LIST STYLES -------------------------------------------------- */ ol, ul { margin: .5em 0em 0em 2em; } li { margin-bottom: .5em; } ul p, ol p, dl p { margin-left: 0em; } ul p.label, ol p.label { margin-top: .5em; } /* -------------------------------------------------- DEFINITION LIST STYLES -------------------------------------------------- */ dl { margin-top: 0em; padding-left: 1px; /* Prevents italic-letter descenders from being cut off */ } dd { margin-bottom: 0em; margin-left: 1.5em; } dt { margin-top: .5em; } /* -------------------------------------------------- CODE, SYNTAX, and REFTIP STYLES -------------------------------------------------- */ pre { margin-top: .5em; margin-bottom: .5em; } pre, code, .code { font: 100% 瀹嬩綋, Courier New, Monospace, Courier;/* This is 100% of 70% */ color: #000066; } pre b, code b { letter-spacing: .1em; /* opens kerning on bold in Syntax/Code */ } pre.syntax { font: 100% Courier New, 瀹嬩綋, Monospace, Courier;/* This is 100% of 70% */ background: #cccccc; padding: 4px 8px; cursor: text; margin-top: 1em; margin-bottom: 1em; color: #000000; border-width: 1px; border-style: solid; border-color: #999999; } /* -------------------------------------------------- LINK STYLES -------------------------------------------------- */ a:link { color: #0000ff; } a:visited { color: #0000ff; } a:hover { color: #3366ff; } /* --------------------------- MSHelp\:link - Help HxLinks --------------------------- */ MSHelp\:link { text-decoration: underline; color: #0000ff; hoverColor: #3366ff; filterString: ; } A.HxLinkTable /* MSHelp\:link - Table disambiguation elements */ { } /* --------------------------- MSHelp\:ktable - Help links --------------------------- */ MSHelp\:ktable { disambiguator: span; separator: &nbsp|&#32; prefix: |&#32; postfix: &nbsp; filterString: ; } div.HxLinkTable { width: auto; /* Forces tables to have correct right margins and top spacing */ margin-top: -.4em; visibility: visible; } ol div.HxLinkTable, ul div.HxLinkTable { margin-top: 0em; /* Forces tables to have correct right margins and top spacing */ } table.HxLinkTable /* Keep in sync with general table settings below */ { width: auto; margin-top: 1.5em; margin-bottom: .3em; margin-left: -1em; border-width: 1px 1px 0px 0px; border-style: solid; border-color: #999999; background-color: #999999; font-size: 100%; /* Text in Table is same size as text outside table */ behavior:url(hxlinktable.htc); /* Attach the behavior to link elements. */ } table.HxLinkTable th, table.HxLinkTable td /* Keep in sync with general table settings below */ { border-style: solid; /* Creates the cell border and color */ border-width: 0px 0px 1px 1px; border-style: solid; border-color: #999999; padding: 4px 6px; text-align: left; } table.HxLinkTable th /* Keep in sync with general table settings below */ { background: #cccccc; /* Creates the shaded table header row */ vertical-align: bottom; } table.HxLinkTable td /* Keep in sync with general table settings below */ { background: #ffffff; vertical-align: top; } /* -------------------------------------------------- TABLE STYLES -------------------------------------------------- */ div.tablediv { width: 100%; /* Forces tables to have correct right margins and top spacing */ margin-top: -.4em; } ol div.tablediv, ul div.tablediv, ol div.HxLinkTable, ul div.HxLinkTable { margin-top: 0em; /* Forces tables to have correct right margins and top spacing */ } table.dtTABLE { width: 100%; /* Forces tables to have correct right margin */ margin-top: .6em; margin-bottom: .3em; border-width: 1px 1px 0px 0px; border-style: solid; border-color: #999999; background-color: #999999; font-size: 100%; /* Text in Table is same size as text outside table */ } table.dtTABLE th, table.dtTABLE td { border-style: solid; /* Creates the cell border and color */ border-width: 0px 0px 1px 1px; border-style: solid; border-color: #999999; padding: 4px 6px; text-align: left; } table.dtTABLE th { background: #cccccc; /* Creates the shaded table header row */ vertical-align: bottom; } table.dtTABLE td { background: #ffffff; vertical-align: top; } /* -------------------------------------------------- ISSUE REPORTING AND MISC LINKS TOPIC FOOTER -------------------------------------------------- */ div.footer { } div.footer hr { color: #999999; height: 1px; } /* -------------------------------------------------- STYLES FOR RUNNING HEADS -------------------------------------------------- */ table.bannerparthead, table.bannertitle /* General values for the Running Head tables */ { position: relative; left: 0px; top: 0px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px; width: 100%; height: 21px; border-collapse: collapse; border-style: solid; border-width: 0px; background-color: #99ccff; font-size: 100%; } table.bannerparthead td /* General Values for cells in the top row of running head */ { margin: 0px 0px 0px 0px; padding: 2px 0px 0px 4px; vertical-align: middle; /*border-width: 0px 0px 1px 0px; */ border-width: 0px border-style: solid; border-color: #999999; background: transparent; /* font-style: normal; */ font-weight: normal; } table.bannerparthead td.product /* Values for top right cell in running head */ { /* Allows for a second text block in the running head */ text-align: right; padding: 2px 5px 0px 5px; } table.bannertitle td /* General Values for cells in the bottom row of running head */ { margin: 0px 0px 0px 0px; padding: 0px 0px 0px 3px; vertical-align: middle; border-width: 0px 0px 1px 0px; border-style: solid; border-color: #999999; background: transparent; font-weight: bold; } td.button1 /* Values for button cells */ { width: 14px; cursor: hand; } /* ================================================= STYLES REQUIRED BY THE SCRIPT */ /* -------------------------------------------------- SAMPLE VIEWER -------------------------------------------------- */ div#smpMgrCell { display:none; } table.SampMgr { margin: 0px 0px 0px -22px; } table.SampMgr td { padding-left: 22px; } /* -------------------------------------------------- RUNNING HEAD BAR POPUP STYLES: See Also, Requirements, MultiLang Filtering -------------------------------------------------- */ div.sapop, div.langMenu /* See Also & Requirements popups */ { position: absolute; left: 0px; z-index: 1; width: 50%; padding: 0px 8px 5px 26px; visibility: hidden; border: 1px solid #999999; /* Same as all other border colors */ background: #ffffcc; } div.langMenu /* MultiLang Filter popup */ { padding: 10px 10px 10px 10px; } div.langMenu ul { list-style-type: none; padding-left: 5px; margin-left: 0px; } .lang, .ilang /* controls the multilang tag styles */ { color: #333333; font-family: Verdana, Arial, 瀹嬩綋, Helvetica, sans-serif; font-size: 80%; font-weight: normal; font-style: normal; } h1 .lang, h1 .ilang { font-size: 80%; } div.filtered { margin-top: .6em; margin-bottom: .6em; margin-left: -7px; padding: 0px 0px 0px 6px; border-left: 1px solid #999999; background: #ffffff; } div.filtered h1, div.filtered h2, div.filtered h3, div.filtered h4 { margin-left: -22px; } div.filtered span.lang { position: relative; left: 0px; } /* -------------------------------------------------- PARAMETER POPUP STYLES -------------------------------------------------- */ div.reftip /* Defines the RefTip popup in Syntax */ { position: absolute; z-index: 1; visibility: hidden; border: 1px solid #999999; background: #ffffcc; /* padding: 0px 0px 0px 0px; */ } div.reftip dl /* Sets margin around the text within the popup */ { margin: 3px 8px 8px 8px; } a.synParam /* parameter popup links */ { color: #0000ff; /* Must match the a:link style color */ text-decoration: underline; } a.synParam:visited /* ensures parameter popup links are always the unvisited color */ { color: #0000ff; /* Must match the a:link style color */ text-decoration: underline; } a.synParam:hover /* parameter popup links */ { color: #3366ff; /* Must match the a:hover style color */ text-decoration: underline; font-style: italic; } /* -------------------------------------------------- EXPAND-COLLAPSE STYLES -------------------------------------------------- */ div.expandBody { margin: .5em 0em 0em 1.4em; display:none; } a.expandLink1 { font-size: 115%; } a#ExPand { color: #3366ff; font-weight: bold; text-decoration: none; } a#ExPandAll { color: #3366ff; font-weight: bold; text-decoration: none; } /* -------------------------------------------------- GLOSSARY POPUP STYLES Not used by Visual Studio .NET -------------------------------------------------- */ /* COMMENT OUT GLOSSARY SECTION /*div#popUpWindow { Controlled by the script in the variable L_PopUpBoxStyle_Style }*/ a.glosslink:link { color: #000000; } a.glosslink:visited { color: #000000; } a.glosslink:hover { color: #000000; font-style: italic; } div#popUpWindow h5 /* Controls the style of the Term in Glossary Popups */ { margin: 5px 5px 5px 5px; color: #000000; } div#popUpWindow p /* Controls the style of the Text in Glossary Popups */ { margin: 5px 5px 5px 5px; color: #000000; } p.GLOSSARY_TEXT { } div#popUpWindow a /* Controls the style of the Links in Glossary Popups */ { } */ /* END COMMENT OUT OF GLOSSARY SECTION */ /* END STYLES REQUIRED BY THE SCRIPT ================================================== */ </style> <HEAD> <META HTTP-EQUIV="Content-Type" Content="text/html; charset=gb2312"> <TITLE>优先级顺序</TITLE> <xml> <MSHelp:TOCTitle <HR><!--Feedback Link--> <p><A HREF="JavaScript:sendfeedback('CHS _731803', 'VSDOCS@MICROSOFT.COM')">将文档反馈发送给 Microsoft</A></p><!--Copyright--> <p><MSHelp:link keywords="vxmscCopyright" TABINDEX="0">&copy; 2002 Microsoft Corporation。保留所有权利。</MSHelp:link></p></div> <!--Closes the footer div--> </div> <!--closes the topic content div--> <!--FOOTER_END--> </BODY> </HTML>


普通字符
区分普通字符与元字符,并说明如何将多个单字符正则表达式组合在一起,以创建更大的表达式。


普通字符包括没有显式指定为元字符的所有可打印和不可打印字符。这包括所有大写和小写字母、所有数字、所有标点符号和一些其他符号。

正则表达式的最简单形式是在搜索字符串中匹配其本身的单个普通字符。例如,单字符模式,如 A,不论出现在搜索字符串中的何处,它总是匹配字母 A。下面是一些单字符正则表达式模式的示例:

/a/
/7/
/M/
可以将许多单字符组合起来以形成大的表达式。例如,以下正则表达式组合了单字符表达式:a、7 和 M。

/a7M/
请注意,没有串联运算符。只须在一个字符后面键入另一个字符。
特殊字符
说明转义符的概念以及如何创建与元字符匹配的正则表达式。


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <HTML xmlns:MSHelp="http://msdn.microsoft.com/mshelp" DIR="LTR"> <style type="text/css"> /* VERSION 9345 Designed for IE5.x. Optimal in IE 6.x CSS for use with Developer Tools Documentation Localizable definitions: font families font sizes */ /* -------------------------------------------------- MAIN TOPIC STYLES -------------------------------------------------- */ div.saveHistory { behavior:url(#default#savehistory); text-decoration: underline } body /* This body tag requires the use of one of the sets of banner and/or text div ids */ { margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; background: #ffffff; color: #000000; font-family: 瀹嬩綋, Verdana, Arial, Helvetica, sans-serif; font-size: 75%; width: 100%; } div#scrollyes /* Allows topic to scroll with correct margins. Cannot be used with running head banner */ { /* Must immediately follow <body>. */ padding: 2px 15px 2px 22px; width: 100%; } div#nsbanner /* Creates Nonscrolling banner region */ { position: relative; left: 0px; padding: 0px 0px 0px 0px; border-bottom: 1px solid #999999; } div#nstext /* Creates the scrolling text area for Nonscrolling region topic */ { padding: 5px 10px 0px 22px; } div#scrbanner /* Creates the running head bar in a full-scroll topic */ { /* Allows topic to scroll. */ margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; border-bottom: 1px solid #999999; } div#scrtext /* Creates the text area in a full-scroll topic */ { /* Allows topic to scroll. */ /* width: 100%; /* Forces tables to have correct right margin */*/ padding: 0px 10px 0px 22px; } div#bannerrow1 /* provides full-width color to top row in running head (requires script) */ { background-color: #99ccff; } div#titlerow /* provides non-scroll topic title area (requires script) */ { width: 100%; /* Forces tables to have correct right margin */ padding: 0px 10px 0px 22px; background-color: #99ccff; } /* -------------------------------------------------- HEADING STYLES -------------------------------------------------- */ h1, h2, h3, h4 { font-family: 瀹嬩綋, Verdana, Arial, Helvetica, sans-serif; margin-bottom: .4em; margin-top: 1em; font-weight: bold; } h1 { font-size: 120%; margin-top: 0em; } div#scrollyes h1 /* Changes font size for full-scrolling topic */ { font-size: 150%; } h2 { font-size: 120%; } h3 { font-size: 115%; } h4 { font-size: 100%; } .dtH1, .dtH2, .dtH3, .dtH4 { margin-left: -18px; } div#titlerow h1 { margin-bottom: .2em } /* -------------------------------------------------- TEXT STYLES -------------------------------------------------- */ p { margin: .5em 0em .5em 0em; } blockquote.dtBlock { margin: .5em 1.5em .5em 1.5em; } div#dtHoverText { color: #000066; } .normal { margin: .5em 0em .5em 0em; } .fineprint { font-size: 110%; /* 90% of 70% */ } .indent { margin: .5em 1.5em .5em 1.5em; } .topicstatus /* Topic Status Boilerplate class */ { display: block; color: red; } /* -------------------------------------------------- LABEL STYLES -------------------------------------------------- */ p.label { margin-top: 1em; } p.labelproc { margin-top: 1em; color: #000066; } /* -------------------------------------------------- GRAPHIC STYLES -------------------------------------------------- */ img { border: none; } /* -------------------------------------------------- LIST STYLES -------------------------------------------------- */ ol, ul { margin: .5em 0em 0em 2em; } li { margin-bottom: .5em; } ul p, ol p, dl p { margin-left: 0em; } ul p.label, ol p.label { margin-top: .5em; } /* -------------------------------------------------- DEFINITION LIST STYLES -------------------------------------------------- */ dl { margin-top: 0em; padding-left: 1px; /* Prevents italic-letter descenders from being cut off */ } dd { margin-bottom: 0em; margin-left: 1.5em; } dt { margin-top: .5em; } /* -------------------------------------------------- CODE, SYNTAX, and REFTIP STYLES -------------------------------------------------- */ pre { margin-top: .5em; margin-bottom: .5em; } pre, code, .code { font: 100% 瀹嬩綋, Courier New, Monospace, Courier;/* This is 100% of 70% */ color: #000066; } pre b, code b { letter-spacing: .1em; /* opens kerning on bold in Syntax/Code */ } pre.syntax { font: 100% Courier New, 瀹嬩綋, Monospace, Courier;/* This is 100% of 70% */ background: #cccccc; padding: 4px 8px; cursor: text; margin-top: 1em; margin-bottom: 1em; color: #000000; border-width: 1px; border-style: solid; border-color: #999999; } /* -------------------------------------------------- LINK STYLES -------------------------------------------------- */ a:link { color: #0000ff; } a:visited { color: #0000ff; } a:hover { color: #3366ff; } /* --------------------------- MSHelp\:link - Help HxLinks --------------------------- */ MSHelp\:link { text-decoration: underline; color: #0000ff; hoverColor: #3366ff; filterString: ; } A.HxLinkTable /* MSHelp\:link - Table disambiguation elements */ { } /* --------------------------- MSHelp\:ktable - Help links --------------------------- */ MSHelp\:ktable { disambiguator: span; separator: &nbsp|&#32; prefix: |&#32; postfix: &nbsp; filterString: ; } div.HxLinkTable { width: auto; /* Forces tables to have correct right margins and top spacing */ margin-top: -.4em; visibility: visible; } ol div.HxLinkTable, ul div.HxLinkTable { margin-top: 0em; /* Forces tables to have correct right margins and top spacing */ } table.HxLinkTable /* Keep in sync with general table settings below */ { width: auto; margin-top: 1.5em; margin-bottom: .3em; margin-left: -1em; border-width: 1px 1px 0px 0px; border-style: solid; border-color: #999999; background-color: #999999; font-size: 100%; /* Text in Table is same size as text outside table */ behavior:url(hxlinktable.htc); /* Attach the behavior to link elements. */ } table.HxLinkTable th, table.HxLinkTable td /* Keep in sync with general table settings below */ { border-style: solid; /* Creates the cell border and color */ border-width: 0px 0px 1px 1px; border-style: solid; border-color: #999999; padding: 4px 6px; text-align: left; } table.HxLinkTable th /* Keep in sync with general table settings below */ { background: #cccccc; /* Creates the shaded table header row */ vertical-align: bottom; } table.HxLinkTable td /* Keep in sync with general table settings below */ { background: #ffffff; vertical-align: top; } /* -------------------------------------------------- TABLE STYLES -------------------------------------------------- */ div.tablediv { width: 100%; /* Forces tables to have correct right margins and top spacing */ margin-top: -.4em; } ol div.tablediv, ul div.tablediv, ol div.HxLinkTable, ul div.HxLinkTable { margin-top: 0em; /* Forces tables to have correct right margins and top spacing */ } table.dtTABLE { width: 100%; /* Forces tables to have correct right margin */ margin-top: .6em; margin-bottom: .3em; border-width: 1px 1px 0px 0px; border-style: solid; border-color: #999999; background-color: #999999; font-size: 100%; /* Text in Table is same size as text outside table */ } table.dtTABLE th, table.dtTABLE td { border-style: solid; /* Creates the cell border and color */ border-width: 0px 0px 1px 1px; border-style: solid; border-color: #999999; padding: 4px 6px; text-align: left; } table.dtTABLE th { background: #cccccc; /* Creates the shaded table header row */ vertical-align: bottom; } table.dtTABLE td { background: #ffffff; vertical-align: top; } /* -------------------------------------------------- ISSUE REPORTING AND MISC LINKS TOPIC FOOTER -------------------------------------------------- */ div.footer { } div.footer hr { color: #999999; height: 1px; } /* -------------------------------------------------- STYLES FOR RUNNING HEADS -------------------------------------------------- */ table.bannerparthead, table.bannertitle /* General values for the Running Head tables */ { position: relative; left: 0px; top: 0px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px; width: 100%; height: 21px; border-collapse: collapse; border-style: solid; border-width: 0px; background-color: #99ccff; font-size: 100%; } table.bannerparthead td /* General Values for cells in the top row of running head */ { margin: 0px 0px 0px 0px; padding: 2px 0px 0px 4px; vertical-align: middle; /*border-width: 0px 0px 1px 0px; */ border-width: 0px border-style: solid; border-color: #999999; background: transparent; /* font-style: normal; */ font-weight: normal; } table.bannerparthead td.product /* Values for top right cell in running head */ { /* Allows for a second text block in the running head */ text-align: right; padding: 2px 5px 0px 5px; } table.bannertitle td /* General Values for cells in the bottom row of running head */ { margin: 0px 0px 0px 0px; padding: 0px 0px 0px 3px; vertical-align: middle; border-width: 0px 0px 1px 0px; border-style: solid; border-color: #999999; background: transparent; font-weight: bold; } td.button1 /* Values for button cells */ { width: 14px; cursor: hand; } /* ================================================= STYLES REQUIRED BY THE SCRIPT */ /* -------------------------------------------------- SAMPLE VIEWER -------------------------------------------------- */ div#smpMgrCell { display:none; } table.SampMgr { margin: 0px 0px 0px -22px; } table.SampMgr td { padding-left: 22px; } /* -------------------------------------------------- RUNNING HEAD BAR POPUP STYLES: See Also, Requirements, MultiLang Filtering -------------------------------------------------- */ div.sapop, div.langMenu /* See Also & Requirements popups */ { position: absolute; left: 0px; z-index: 1; width: 50%; padding: 0px 8px 5px 26px; visibility: hidden; border: 1px solid #999999; /* Same as all other border colors */ background: #ffffcc; } div.langMenu /* MultiLang Filter popup */ { padding: 10px 10px 10px 10px; } div.langMenu ul { list-style-type: none; padding-left: 5px; margin-left: 0px; } .lang, .ilang /* controls the multilang tag styles */ { color: #333333; font-family: Verdana, Arial, 瀹嬩綋, Helvetica, sans-serif; font-size: 80%; font-weight: normal; font-style: normal; } h1 .lang, h1 .ilang { font-size: 80%; } div.filtered { margin-top: .6em; margin-bottom: .6em; margin-left: -7px; padding: 0px 0px 0px 6px; border-left: 1px solid #999999; background: #ffffff; } div.filtered h1, div.filtered h2, div.filtered h3, div.filtered h4 { margin-left: -22px; } div.filtered span.lang { position: relative; left: 0px; } /* -------------------------------------------------- PARAMETER POPUP STYLES -------------------------------------------------- */ div.reftip /* Defines the RefTip popup in Syntax */ { position: absolute; z-index: 1; visibility: hidden; border: 1px solid #999999; background: #ffffcc; /* padding: 0px 0px 0px 0px; */ } div.reftip dl /* Sets margin around the text within the popup */ { margin: 3px 8px 8px 8px; } a.synParam /* parameter popup links */ { color: #0000ff; /* Must match the a:link style color */ text-decoration: underline; } a.synParam:visited /* ensures parameter popup links are always the unvisited color */ { color: #0000ff; /* Must match the a:link style color */ text-decoration: underline; } a.synParam:hover /* parameter popup links */ { color: #3366ff; /* Must match the a:hover style color */ text-decoration: underline; font-style: italic; } /* -------------------------------------------------- EXPAND-COLLAPSE STYLES -------------------------------------------------- */ div.expandBody { margin: .5em 0em 0em 1.4em; display:none; } a.expandLink1 { font-size: 115%; } a#ExPand { color: #3366ff; font-weight: bold; text-decoration: none; } a#ExPandAll { color: #3366ff; font-weight: bold; text-decoration: none; } /* -------------------------------------------------- GLOSSARY POPUP STYLES Not used by Visual Studio .NET -------------------------------------------------- */ /* COMMENT OUT GLOSSARY SECTION /*div#popUpWindow { Controlled by the script in the variable L_PopUpBoxStyle_Style }*/ a.glosslink:link { color: #000000; } a.glosslink:visited { color: #000000; } a.glosslink:hover { color: #000000; font-style: italic; } div#popUpWindow h5 /* Controls the style of the Term in Glossary Popups */ { margin: 5px 5px 5px 5px; color: #000000; } div#popUpWindow p /* Controls the style of the Text in Glossary Popups */ { margin: 5px 5px 5px 5px; color: #000000; } p.GLOSSARY_TEXT { } div#popUpWindow a /* Controls the style of the Links in Glossary Popups */ { } */ /* END COMMENT OUT OF GLOSSARY SECTION */ /* END STYLES REQUIRED BY THE SCRIPT ================================================== */ </style> <HEAD> <META HTTP-EQUIV="Content-Type" Content="text/html; charset=gb2312"> <TITLE>特殊字符</TITLE> <xml> <MSHelp:TOCTitle <HR><!--Feedback Link--> <p><A HREF="JavaScript:sendfeedback('CHS _731805', 'VSDOCS@MICROSOFT.COM')">将文档反馈发送给 Microsoft</A></p><!--Copyright--> <p><MSHelp:link keywords="vxmscCopyright" TABINDEX="0">&copy; 2002 Microsoft Corporation。保留所有权利。</MSHelp:link></p></div> <!--Closes the footer div--> </div> <!--closes the topic content div--> <!--FOOTER_END--> </BODY> </HTML>



不可打印字符 
列出用于表示正则表达式中非打印字符的转义序列。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <HTML xmlns:MSHelp="http://msdn.microsoft.com/mshelp" DIR="LTR"> <style type="text/css"> /* VERSION 9345 Designed for IE5.x. Optimal in IE 6.x CSS for use with Developer Tools Documentation Localizable definitions: font families font sizes */ /* -------------------------------------------------- MAIN TOPIC STYLES -------------------------------------------------- */ div.saveHistory { behavior:url(#default#savehistory); text-decoration: underline } body /* This body tag requires the use of one of the sets of banner and/or text div ids */ { margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; background: #ffffff; color: #000000; font-family: 瀹嬩綋, Verdana, Arial, Helvetica, sans-serif; font-size: 75%; width: 100%; } div#scrollyes /* Allows topic to scroll with correct margins. Cannot be used with running head banner */ { /* Must immediately follow <body>. */ padding: 2px 15px 2px 22px; width: 100%; } div#nsbanner /* Creates Nonscrolling banner region */ { position: relative; left: 0px; padding: 0px 0px 0px 0px; border-bottom: 1px solid #999999; } div#nstext /* Creates the scrolling text area for Nonscrolling region topic */ { padding: 5px 10px 0px 22px; } div#scrbanner /* Creates the running head bar in a full-scroll topic */ { /* Allows topic to scroll. */ margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; border-bottom: 1px solid #999999; } div#scrtext /* Creates the text area in a full-scroll topic */ { /* Allows topic to scroll. */ /* width: 100%; /* Forces tables to have correct right margin */*/ padding: 0px 10px 0px 22px; } div#bannerrow1 /* provides full-width color to top row in running head (requires script) */ { background-color: #99ccff; } div#titlerow /* provides non-scroll topic title area (requires script) */ { width: 100%; /* Forces tables to have correct right margin */ padding: 0px 10px 0px 22px; background-color: #99ccff; } /* -------------------------------------------------- HEADING STYLES -------------------------------------------------- */ h1, h2, h3, h4 { font-family: 瀹嬩綋, Verdana, Arial, Helvetica, sans-serif; margin-bottom: .4em; margin-top: 1em; font-weight: bold; } h1 { font-size: 120%; margin-top: 0em; } div#scrollyes h1 /* Changes font size for full-scrolling topic */ { font-size: 150%; } h2 { font-size: 120%; } h3 { font-size: 115%; } h4 { font-size: 100%; } .dtH1, .dtH2, .dtH3, .dtH4 { margin-left: -18px; } div#titlerow h1 { margin-bottom: .2em } /* -------------------------------------------------- TEXT STYLES -------------------------------------------------- */ p { margin: .5em 0em .5em 0em; } blockquote.dtBlock { margin: .5em 1.5em .5em 1.5em; } div#dtHoverText { color: #000066; } .normal { margin: .5em 0em .5em 0em; } .fineprint { font-size: 110%; /* 90% of 70% */ } .indent { margin: .5em 1.5em .5em 1.5em; } .topicstatus /* Topic Status Boilerplate class */ { display: block; color: red; } /* -------------------------------------------------- LABEL STYLES -------------------------------------------------- */ p.label { margin-top: 1em; } p.labelproc { margin-top: 1em; color: #000066; } /* -------------------------------------------------- GRAPHIC STYLES -------------------------------------------------- */ img { border: none; } /* -------------------------------------------------- LIST STYLES -------------------------------------------------- */ ol, ul { margin: .5em 0em 0em 2em; } li { margin-bottom: .5em; } ul p, ol p, dl p { margin-left: 0em; } ul p.label, ol p.label { margin-top: .5em; } /* -------------------------------------------------- DEFINITION LIST STYLES -------------------------------------------------- */ dl { margin-top: 0em; padding-left: 1px; /* Prevents italic-letter descenders from being cut off */ } dd { margin-bottom: 0em; margin-left: 1.5em; } dt { margin-top: .5em; } /* -------------------------------------------------- CODE, SYNTAX, and REFTIP STYLES -------------------------------------------------- */ pre { margin-top: .5em; margin-bottom: .5em; } pre, code, .code { font: 100% 瀹嬩綋, Courier New, Monospace, Courier;/* This is 100% of 70% */ color: #000066; } pre b, code b { letter-spacing: .1em; /* opens kerning on bold in Syntax/Code */ } pre.syntax { font: 100% Courier New, 瀹嬩綋, Monospace, Courier;/* This is 100% of 70% */ background: #cccccc; padding: 4px 8px; cursor: text; margin-top: 1em; margin-bottom: 1em; color: #000000; border-width: 1px; border-style: solid; border-color: #999999; } /* -------------------------------------------------- LINK STYLES -------------------------------------------------- */ a:link { color: #0000ff; } a:visited { color: #0000ff; } a:hover { color: #3366ff; } /* --------------------------- MSHelp\:link - Help HxLinks --------------------------- */ MSHelp\:link { text-decoration: underline; color: #0000ff; hoverColor: #3366ff; filterString: ; } A.HxLinkTable /* MSHelp\:link - Table disambiguation elements */ { } /* --------------------------- MSHelp\:ktable - Help links --------------------------- */ MSHelp\:ktable { disambiguator: span; separator: &nbsp|&#32; prefix: |&#32; postfix: &nbsp; filterString: ; } div.HxLinkTable { width: auto; /* Forces tables to have correct right margins and top spacing */ margin-top: -.4em; visibility: visible; } ol div.HxLinkTable, ul div.HxLinkTable { margin-top: 0em; /* Forces tables to have correct right margins and top spacing */ } table.HxLinkTable /* Keep in sync with general table settings below */ { width: auto; margin-top: 1.5em; margin-bottom: .3em; margin-left: -1em; border-width: 1px 1px 0px 0px; border-style: solid; border-color: #999999; background-color: #999999; font-size: 100%; /* Text in Table is same size as text outside table */ behavior:url(hxlinktable.htc); /* Attach the behavior to link elements. */ } table.HxLinkTable th, table.HxLinkTable td /* Keep in sync with general table settings below */ { border-style: solid; /* Creates the cell border and color */ border-width: 0px 0px 1px 1px; border-style: solid; border-color: #999999; padding: 4px 6px; text-align: left; } table.HxLinkTable th /* Keep in sync with general table settings below */ { background: #cccccc; /* Creates the shaded table header row */ vertical-align: bottom; } table.HxLinkTable td /* Keep in sync with general table settings below */ { background: #ffffff; vertical-align: top; } /* -------------------------------------------------- TABLE STYLES -------------------------------------------------- */ div.tablediv { width: 100%; /* Forces tables to have correct right margins and top spacing */ margin-top: -.4em; } ol div.tablediv, ul div.tablediv, ol div.HxLinkTable, ul div.HxLinkTable { margin-top: 0em; /* Forces tables to have correct right margins and top spacing */ } table.dtTABLE { width: 100%; /* Forces tables to have correct right margin */ margin-top: .6em; margin-bottom: .3em; border-width: 1px 1px 0px 0px; border-style: solid; border-color: #999999; background-color: #999999; font-size: 100%; /* Text in Table is same size as text outside table */ } table.dtTABLE th, table.dtTABLE td { border-style: solid; /* Creates the cell border and color */ border-width: 0px 0px 1px 1px; border-style: solid; border-color: #999999; padding: 4px 6px; text-align: left; } table.dtTABLE th { background: #cccccc; /* Creates the shaded table header row */ vertical-align: bottom; } table.dtTABLE td { background: #ffffff; vertical-align: top; } /* -------------------------------------------------- ISSUE REPORTING AND MISC LINKS TOPIC FOOTER -------------------------------------------------- */ div.footer { } div.footer hr { color: #999999; height: 1px; } /* -------------------------------------------------- STYLES FOR RUNNING HEADS -------------------------------------------------- */ table.bannerparthead, table.bannertitle /* General values for the Running Head tables */ { position: relative; left: 0px; top: 0px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px; width: 100%; height: 21px; border-collapse: collapse; border-style: solid; border-width: 0px; background-color: #99ccff; font-size: 100%; } table.bannerparthead td /* General Values for cells in the top row of running head */ { margin: 0px 0px 0px 0px; padding: 2px 0px 0px 4px; vertical-align: middle; /*border-width: 0px 0px 1px 0px; */ border-width: 0px border-style: solid; border-color: #999999; background: transparent; /* font-style: normal; */ font-weight: normal; } table.bannerparthead td.product /* Values for top right cell in running head */ { /* Allows for a second text block in the running head */ text-align: right; padding: 2px 5px 0px 5px; } table.bannertitle td /* General Values for cells in the bottom row of running head */ { margin: 0px 0px 0px 0px; padding: 0px 0px 0px 3px; vertical-align: middle; border-width: 0px 0px 1px 0px; border-style: solid; border-color: #999999; background: transparent; font-weight: bold; } td.button1 /* Values for button cells */ { width: 14px; cursor: hand; } /* ================================================= STYLES REQUIRED BY THE SCRIPT */ /* -------------------------------------------------- SAMPLE VIEWER -------------------------------------------------- */ div#smpMgrCell { display:none; } table.SampMgr { margin: 0px 0px 0px -22px; } table.SampMgr td { padding-left: 22px; } /* -------------------------------------------------- RUNNING HEAD BAR POPUP STYLES: See Also, Requirements, MultiLang Filtering -------------------------------------------------- */ div.sapop, div.langMenu /* See Also & Requirements popups */ { position: absolute; left: 0px; z-index: 1; width: 50%; padding: 0px 8px 5px 26px; visibility: hidden; border: 1px solid #999999; /* Same as all other border colors */ background: #ffffcc; } div.langMenu /* MultiLang Filter popup */ { padding: 10px 10px 10px 10px; } div.langMenu ul { list-style-type: none; padding-left: 5px; margin-left: 0px; } .lang, .ilang /* controls the multilang tag styles */ { color: #333333; font-family: Verdana, Arial, 瀹嬩綋, Helvetica, sans-serif; font-size: 80%; font-weight: normal; font-style: normal; } h1 .lang, h1 .ilang { font-size: 80%; } div.filtered { margin-top: .6em; margin-bottom: .6em; margin-left: -7px; padding: 0px 0px 0px 6px; border-left: 1px solid #999999; background: #ffffff; } div.filtered h1, div.filtered h2, div.filtered h3, div.filtered h4 { margin-left: -22px; } div.filtered span.lang { position: relative; left: 0px; } /* -------------------------------------------------- PARAMETER POPUP STYLES -------------------------------------------------- */ div.reftip /* Defines the RefTip popup in Syntax */ { position: absolute; z-index: 1; visibility: hidden; border: 1px solid #999999; background: #ffffcc; /* padding: 0px 0px 0px 0px; */ } div.reftip dl /* Sets margin around the text within the popup */ { margin: 3px 8px 8px 8px; } a.synParam /* parameter popup links */ { color: #0000ff; /* Must match the a:link style color */ text-decoration: underline; } a.synParam:visited /* ensures parameter popup links are always the unvisited color */ { color: #0000ff; /* Must match the a:link style color */ text-decoration: underline; } a.synParam:hover /* parameter popup links */ { color: #3366ff; /* Must match the a:hover style color */ text-decoration: underline; font-style: italic; } /* -------------------------------------------------- EXPAND-COLLAPSE STYLES -------------------------------------------------- */ div.expandBody { margin: .5em 0em 0em 1.4em; display:none; } a.expandLink1 { font-size: 115%; } a#ExPand { color: #3366ff; font-weight: bold; text-decoration: none; } a#ExPandAll { color: #3366ff; font-weight: bold; text-decoration: none; } /* -------------------------------------------------- GLOSSARY POPUP STYLES Not used by Visual Studio .NET -------------------------------------------------- */ /* COMMENT OUT GLOSSARY SECTION /*div#popUpWindow { Controlled by the script in the variable L_PopUpBoxStyle_Style }*/ a.glosslink:link { color: #000000; } a.glosslink:visited { color: #000000; } a.glosslink:hover { color: #000000; font-style: italic; } div#popUpWindow h5 /* Controls the style of the Term in Glossary Popups */ { margin: 5px 5px 5px 5px; color: #000000; } div#popUpWindow p /* Controls the style of the Text in Glossary Popups */ { margin: 5px 5px 5px 5px; color: #000000; } p.GLOSSARY_TEXT { } div#popUpWindow a /* Controls the style of the Links in Glossary Popups */ { } */ /* END COMMENT OUT OF GLOSSARY SECTION */ /* END STYLES REQUIRED BY THE SCRIPT ================================================== */ </style> <HEAD> <META HTTP-EQUIV="Content-Type" Content="text/html; charset=gb2312"> <TITLE>不可打印字符</TITLE> <xml> <MSHelp:TOCTitle <HR><!--Feedback Link--> <p><A HREF="JavaScript:sendfeedback('CHS _731806', 'VSDOCS@MICROSOFT.COM')">将文档反馈发送给 Microsoft</A></p><!--Copyright--> <p><MSHelp:link keywords="vxmscCopyright" TABINDEX="0">&copy; 2002 Microsoft Corporation。保留所有权利。</MSHelp:link></p></div> <!--Closes the footer div--> </div> <!--closes the topic content div--> <!--FOOTER_END--> </BODY> </HTML>


字符匹配 
说明正则表达式如何使用句点、转义符和中括号创建返回特定结果的序列。

句点 (.) 匹配字符串中的各种打印或非打印字符,只有一个字符例外。这个例外就是换行符 (\n)。下面的正则表达式匹配 aac、abc、acc、adc 等等,以及 a1c、a2c、a-c 和 a#c:

/a.c/
若要匹配包含文件名的字符串,而句点 (.) 是输入字符串的组成部分,请在正则表达式中的句点前面加反斜扛 (\) 字符。举例来说明,下面的正则表达式匹配 filename.ext:

/filename\.ext/
这些表达式只让您匹配[任何]单个字符。可能需要匹配列表中的特定字符组。例如,可能需要查找用数字表示的章节标题(Chapter 1、Chapter 2 等等)。

中括号表达式
若要创建匹配字符组的一个列表,请在方括号([ 和 ])内放置一个或更多单个字符。当字符括在中括号内时,该列表称为[中括号表达式]。与在任何别的位置一样,普通字符在中括号内表示其本身,即,它在输入文本中匹配一次其本身。大多数特殊字符在中括号表达式内出现时失去它们的意义。不过也有一些例外,如: 

如果 ] 字符不是第一项,它结束一个列表。若要匹配列表中的 ] 字符,请将它放在第一位,紧跟在开始 [ 后面。 
\ 字符继续作为转义符。若要匹配 \ 字符,请使用 \\。 
括在中括号表达式中的字符只匹配处于正则表达式中该位置的单个字符。以下正则表达式匹配 Chapter 1、Chapter 2、Chapter 3、Chapter 4 和 Chapter 5:

/Chapter [12345]/
请注意,单词 Chapter 和后面的空格的位置相对于中括号内的字符是固定的。中括号表达式指定的只是匹配紧跟在单词 Chapter 和空格后面的单个字符位置的字符集。这是第九个字符位置。

若要使用范围代替字符本身来表示匹配字符组,请使用连字符 (-) 将范围中的开始字符和结束字符分开。单个字符的字符值确定范围内的相对顺序。下面的正则表达式包含范围表达式,该范围表达式等效于上面显示的中括号中的列表。

/Chapter [1-5]/
当以这种方式指定范围时,开始值和结束值两者都包括在范围内。注意,还有一点很重要,按 Unicode 排序顺序,开始值必须在结束值的前面。

若要在中括号表达式中包括连字符,请采用下列方法之一: 

用反斜扛将它转义: 
[\-]
将连字符放在中括号列表的开始或结尾。下面的表达式匹配所有小写字母和连字符: 
[-a-z]
[a-z-]
创建一个范围,在该范围中,开始字符值小于连字符,而结束字符值等于或大于连字符。下面的两个正则表达式都满足这一要求: 
[!--]
[!-~]
若要查找不在列表或范围内的所有字符,请将插入符号 (^) 放在列表的开头。如果插入字符出现在列表中的其他任何位置,则它匹配其本身。下面的正则表达式匹配编号大于 5 的章节标题:

/Chapter [^12345]/
在上面的示例中,表达式在第九个位置匹配 1、2、3、4 或 5 之外的任何数字字符。这样,例如,Chapter 7 就是一个匹配项,Chapter 9 也是一个匹配项。

上面的表达式可以使用连字符 (-) 来表示:

/Chapter [^1-5]/
中括号表达式的典型用途是指定任何大写或小写字母或任何数字的匹配。下面的表达式指定这样的匹配:

/[A-Za-z0-9]/
限定符 
说明当无法指定多少字符构成一个匹配时如何创建正则表达式。 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <HTML xmlns:MSHelp="http://msdn.microsoft.com/mshelp" DIR="LTR"> <style type="text/css"> /* VERSION 9345 Designed for IE5.x. Optimal in IE 6.x CSS for use with Developer Tools Documentation Localizable definitions: font families font sizes */ /* -------------------------------------------------- MAIN TOPIC STYLES -------------------------------------------------- */ div.saveHistory { behavior:url(#default#savehistory); text-decoration: underline } body /* This body tag requires the use of one of the sets of banner and/or text div ids */ { margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; background: #ffffff; color: #000000; font-family: 瀹嬩綋, Verdana, Arial, Helvetica, sans-serif; font-size: 75%; width: 100%; } div#scrollyes /* Allows topic to scroll with correct margins. Cannot be used with running head banner */ { /* Must immediately follow <body>. */ padding: 2px 15px 2px 22px; width: 100%; } div#nsbanner /* Creates Nonscrolling banner region */ { position: relative; left: 0px; padding: 0px 0px 0px 0px; border-bottom: 1px solid #999999; } div#nstext /* Creates the scrolling text area for Nonscrolling region topic */ { padding: 5px 10px 0px 22px; } div#scrbanner /* Creates the running head bar in a full-scroll topic */ { /* Allows topic to scroll. */ margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; border-bottom: 1px solid #999999; } div#scrtext /* Creates the text area in a full-scroll topic */ { /* Allows topic to scroll. */ /* width: 100%; /* Forces tables to have correct right margin */*/ padding: 0px 10px 0px 22px; } div#bannerrow1 /* provides full-width color to top row in running head (requires script) */ { background-color: #99ccff; } div#titlerow /* provides non-scroll topic title area (requires script) */ { width: 100%; /* Forces tables to have correct right margin */ padding: 0px 10px 0px 22px; background-color: #99ccff; } /* -------------------------------------------------- HEADING STYLES -------------------------------------------------- */ h1, h2, h3, h4 { font-family: 瀹嬩綋, Verdana, Arial, Helvetica, sans-serif; margin-bottom: .4em; margin-top: 1em; font-weight: bold; } h1 { font-size: 120%; margin-top: 0em; } div#scrollyes h1 /* Changes font size for full-scrolling topic */ { font-size: 150%; } h2 { font-size: 120%; } h3 { font-size: 115%; } h4 { font-size: 100%; } .dtH1, .dtH2, .dtH3, .dtH4 { margin-left: -18px; } div#titlerow h1 { margin-bottom: .2em } /* -------------------------------------------------- TEXT STYLES -------------------------------------------------- */ p { margin: .5em 0em .5em 0em; } blockquote.dtBlock { margin: .5em 1.5em .5em 1.5em; } div#dtHoverText { color: #000066; } .normal { margin: .5em 0em .5em 0em; } .fineprint { font-size: 110%; /* 90% of 70% */ } .indent { margin: .5em 1.5em .5em 1.5em; } .topicstatus /* Topic Status Boilerplate class */ { display: block; color: red; } /* -------------------------------------------------- LABEL STYLES -------------------------------------------------- */ p.label { margin-top: 1em; } p.labelproc { margin-top: 1em; color: #000066; } /* -------------------------------------------------- GRAPHIC STYLES -------------------------------------------------- */ img { border: none; } /* -------------------------------------------------- LIST STYLES -------------------------------------------------- */ ol, ul { margin: .5em 0em 0em 2em; } li { margin-bottom: .5em; } ul p, ol p, dl p { margin-left: 0em; } ul p.label, ol p.label { margin-top: .5em; } /* -------------------------------------------------- DEFINITION LIST STYLES -------------------------------------------------- */ dl { margin-top: 0em; padding-left: 1px; /* Prevents italic-letter descenders from being cut off */ } dd { margin-bottom: 0em; margin-left: 1.5em; } dt { margin-top: .5em; } /* -------------------------------------------------- CODE, SYNTAX, and REFTIP STYLES -------------------------------------------------- */ pre { margin-top: .5em; margin-bottom: .5em; } pre, code, .code { font: 100% 瀹嬩綋, Courier New, Monospace, Courier;/* This is 100% of 70% */ color: #000066; } pre b, code b { letter-spacing: .1em; /* opens kerning on bold in Syntax/Code */ } pre.syntax { font: 100% Courier New, 瀹嬩綋, Monospace, Courier;/* This is 100% of 70% */ background: #cccccc; padding: 4px 8px; cursor: text; margin-top: 1em; margin-bottom: 1em; color: #000000; border-width: 1px; border-style: solid; border-color: #999999; } /* -------------------------------------------------- LINK STYLES -------------------------------------------------- */ a:link { color: #0000ff; } a:visited { color: #0000ff; } a:hover { color: #3366ff; } /* --------------------------- MSHelp\:link - Help HxLinks --------------------------- */ MSHelp\:link { text-decoration: underline; color: #0000ff; hoverColor: #3366ff; filterString: ; } A.HxLinkTable /* MSHelp\:link - Table disambiguation elements */ { } /* --------------------------- MSHelp\:ktable - Help links --------------------------- */ MSHelp\:ktable { disambiguator: span; separator: &nbsp|&#32; prefix: |&#32; postfix: &nbsp; filterString: ; } div.HxLinkTable { width: auto; /* Forces tables to have correct right margins and top spacing */ margin-top: -.4em; visibility: visible; } ol div.HxLinkTable, ul div.HxLinkTable { margin-top: 0em; /* Forces tables to have correct right margins and top spacing */ } table.HxLinkTable /* Keep in sync with general table settings below */ { width: auto; margin-top: 1.5em; margin-bottom: .3em; margin-left: -1em; border-width: 1px 1px 0px 0px; border-style: solid; border-color: #999999; background-color: #999999; font-size: 100%; /* Text in Table is same size as text outside table */ behavior:url(hxlinktable.htc); /* Attach the behavior to link elements. */ } table.HxLinkTable th, table.HxLinkTable td /* Keep in sync with general table settings below */ { border-style: solid; /* Creates the cell border and color */ border-width: 0px 0px 1px 1px; border-style: solid; border-color: #999999; padding: 4px 6px; text-align: left; } table.HxLinkTable th /* Keep in sync with general table settings below */ { background: #cccccc; /* Creates the shaded table header row */ vertical-align: bottom; } table.HxLinkTable td /* Keep in sync with general table settings below */ { background: #ffffff; vertical-align: top; } /* -------------------------------------------------- TABLE STYLES -------------------------------------------------- */ div.tablediv { width: 100%; /* Forces tables to have correct right margins and top spacing */ margin-top: -.4em; } ol div.tablediv, ul div.tablediv, ol div.HxLinkTable, ul div.HxLinkTable { margin-top: 0em; /* Forces tables to have correct right margins and top spacing */ } table.dtTABLE { width: 100%; /* Forces tables to have correct right margin */ margin-top: .6em; margin-bottom: .3em; border-width: 1px 1px 0px 0px; border-style: solid; border-color: #999999; background-color: #999999; font-size: 100%; /* Text in Table is same size as text outside table */ } table.dtTABLE th, table.dtTABLE td { border-style: solid; /* Creates the cell border and color */ border-width: 0px 0px 1px 1px; border-style: solid; border-color: #999999; padding: 4px 6px; text-align: left; } table.dtTABLE th { background: #cccccc; /* Creates the shaded table header row */ vertical-align: bottom; } table.dtTABLE td { background: #ffffff; vertical-align: top; } /* -------------------------------------------------- ISSUE REPORTING AND MISC LINKS TOPIC FOOTER -------------------------------------------------- */ div.footer { } div.footer hr { color: #999999; height: 1px; } /* -------------------------------------------------- STYLES FOR RUNNING HEADS -------------------------------------------------- */ table.bannerparthead, table.bannertitle /* General values for the Running Head tables */ { position: relative; left: 0px; top: 0px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px; width: 100%; height: 21px; border-collapse: collapse; border-style: solid; border-width: 0px; background-color: #99ccff; font-size: 100%; } table.bannerparthead td /* General Values for cells in the top row of running head */ { margin: 0px 0px 0px 0px; padding: 2px 0px 0px 4px; vertical-align: middle; /*border-width: 0px 0px 1px 0px; */ border-width: 0px border-style: solid; border-color: #999999; background: transparent; /* font-style: normal; */ font-weight: normal; } table.bannerparthead td.product /* Values for top right cell in running head */ { /* Allows for a second text block in the running head */ text-align: right; padding: 2px 5px 0px 5px; } table.bannertitle td /* General Values for cells in the bottom row of running head */ { margin: 0px 0px 0px 0px; padding: 0px 0px 0px 3px; vertical-align: middle; border-width: 0px 0px 1px 0px; border-style: solid; border-color: #999999; background: transparent; font-weight: bold; } td.button1 /* Values for button cells */ { width: 14px; cursor: hand; } /* ================================================= STYLES REQUIRED BY THE SCRIPT */ /* -------------------------------------------------- SAMPLE VIEWER -------------------------------------------------- */ div#smpMgrCell { display:none; } table.SampMgr { margin: 0px 0px 0px -22px; } table.SampMgr td { padding-left: 22px; } /* -------------------------------------------------- RUNNING HEAD BAR POPUP STYLES: See Also, Requirements, MultiLang Filtering -------------------------------------------------- */ div.sapop, div.langMenu /* See Also & Requirements popups */ { position: absolute; left: 0px; z-index: 1; width: 50%; padding: 0px 8px 5px 26px; visibility: hidden; border: 1px solid #999999; /* Same as all other border colors */ background: #ffffcc; } div.langMenu /* MultiLang Filter popup */ { padding: 10px 10px 10px 10px; } div.langMenu ul { list-style-type: none; padding-left: 5px; margin-left: 0px; } .lang, .ilang /* controls the multilang tag styles */ { color: #333333; font-family: Verdana, Arial, 瀹嬩綋, Helvetica, sans-serif; font-size: 80%; font-weight: normal; font-style: normal; } h1 .lang, h1 .ilang { font-size: 80%; } div.filtered { margin-top: .6em; margin-bottom: .6em; margin-left: -7px; padding: 0px 0px 0px 6px; border-left: 1px solid #999999; background: #ffffff; } div.filtered h1, div.filtered h2, div.filtered h3, div.filtered h4 { margin-left: -22px; } div.filtered span.lang { position: relative; left: 0px; } /* -------------------------------------------------- PARAMETER POPUP STYLES -------------------------------------------------- */ div.reftip /* Defines the RefTip popup in Syntax */ { position: absolute; z-index: 1; visibility: hidden; border: 1px solid #999999; background: #ffffcc; /* padding: 0px 0px 0px 0px; */ } div.reftip dl /* Sets margin around the text within the popup */ { margin: 3px 8px 8px 8px; } a.synParam /* parameter popup links */ { color: #0000ff; /* Must match the a:link style color */ text-decoration: underline; } a.synParam:visited /* ensures parameter popup links are always the unvisited color */ { color: #0000ff; /* Must match the a:link style color */ text-decoration: underline; } a.synParam:hover /* parameter popup links */ { color: #3366ff; /* Must match the a:hover style color */ text-decoration: underline; font-style: italic; } /* -------------------------------------------------- EXPAND-COLLAPSE STYLES -------------------------------------------------- */ div.expandBody { margin: .5em 0em 0em 1.4em; display:none; } a.expandLink1 { font-size: 115%; } a#ExPand { color: #3366ff; font-weight: bold; text-decoration: none; } a#ExPandAll { color: #3366ff; font-weight: bold; text-decoration: none; } /* -------------------------------------------------- GLOSSARY POPUP STYLES Not used by Visual Studio .NET -------------------------------------------------- */ /* COMMENT OUT GLOSSARY SECTION /*div#popUpWindow { Controlled by the script in the variable L_PopUpBoxStyle_Style }*/ a.glosslink:link { color: #000000; } a.glosslink:visited { color: #000000; } a.glosslink:hover { color: #000000; font-style: italic; } div#popUpWindow h5 /* Controls the style of the Term in Glossary Popups */ { margin: 5px 5px 5px 5px; color: #000000; } div#popUpWindow p /* Controls the style of the Text in Glossary Popups */ { margin: 5px 5px 5px 5px; color: #000000; } p.GLOSSARY_TEXT { } div#popUpWindow a /* Controls the style of the Links in Glossary Popups */ { } */ /* END COMMENT OUT OF GLOSSARY SECTION */ /* END STYLES REQUIRED BY THE SCRIPT ================================================== */ </style> <HEAD> <META HTTP-EQUIV="Content-Type" Content="text/html; charset=gb2312"> <TITLE>限定符</TITLE> <xml> <MSHelp:TOCTitle <HR><!--Feedback Link--> <p><A HREF="JavaScript:sendfeedback('CHS _731808', 'VSDOCS@MICROSOFT.COM')">将文档反馈发送给 Microsoft</A></p><!--Copyright--> <p><MSHelp:link keywords="vxmscCopyright" TABINDEX="0">&copy; 2002 Microsoft Corporation。保留所有权利。</MSHelp:link></p></div> <!--Closes the footer div--> </div> <!--closes the topic content div--> <!--FOOTER_END--> </BODY> </HTML>


定位点 
说明如何将正则表达式固定到行首或行尾,以及如何创建在单词内、在单词的开头或者在单词的结尾出现的正则表达式。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <HTML xmlns:MSHelp="http://msdn.microsoft.com/mshelp" DIR="LTR"> <style type="text/css"> /* VERSION 9345 Designed for IE5.x. Optimal in IE 6.x CSS for use with Developer Tools Documentation Localizable definitions: font families font sizes */ /* -------------------------------------------------- MAIN TOPIC STYLES -------------------------------------------------- */ div.saveHistory { behavior:url(#default#savehistory); text-decoration: underline } body /* This body tag requires the use of one of the sets of banner and/or text div ids */ { margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; background: #ffffff; color: #000000; font-family: 瀹嬩綋, Verdana, Arial, Helvetica, sans-serif; font-size: 75%; width: 100%; } div#scrollyes /* Allows topic to scroll with correct margins. Cannot be used with running head banner */ { /* Must immediately follow <body>. */ padding: 2px 15px 2px 22px; width: 100%; } div#nsbanner /* Creates Nonscrolling banner region */ { position: relative; left: 0px; padding: 0px 0px 0px 0px; border-bottom: 1px solid #999999; } div#nstext /* Creates the scrolling text area for Nonscrolling region topic */ { padding: 5px 10px 0px 22px; } div#scrbanner /* Creates the running head bar in a full-scroll topic */ { /* Allows topic to scroll. */ margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; border-bottom: 1px solid #999999; } div#scrtext /* Creates the text area in a full-scroll topic */ { /* Allows topic to scroll. */ /* width: 100%; /* Forces tables to have correct right margin */*/ padding: 0px 10px 0px 22px; } div#bannerrow1 /* provides full-width color to top row in running head (requires script) */ { background-color: #99ccff; } div#titlerow /* provides non-scroll topic title area (requires script) */ { width: 100%; /* Forces tables to have correct right margin */ padding: 0px 10px 0px 22px; background-color: #99ccff; } /* -------------------------------------------------- HEADING STYLES -------------------------------------------------- */ h1, h2, h3, h4 { font-family: 瀹嬩綋, Verdana, Arial, Helvetica, sans-serif; margin-bottom: .4em; margin-top: 1em; font-weight: bold; } h1 { font-size: 120%; margin-top: 0em; } div#scrollyes h1 /* Changes font size for full-scrolling topic */ { font-size: 150%; } h2 { font-size: 120%; } h3 { font-size: 115%; } h4 { font-size: 100%; } .dtH1, .dtH2, .dtH3, .dtH4 { margin-left: -18px; } div#titlerow h1 { margin-bottom: .2em } /* -------------------------------------------------- TEXT STYLES -------------------------------------------------- */ p { margin: .5em 0em .5em 0em; } blockquote.dtBlock { margin: .5em 1.5em .5em 1.5em; } div#dtHoverText { color: #000066; } .normal { margin: .5em 0em .5em 0em; } .fineprint { font-size: 110%; /* 90% of 70% */ } .indent { margin: .5em 1.5em .5em 1.5em; } .topicstatus /* Topic Status Boilerplate class */ { display: block; color: red; } /* -------------------------------------------------- LABEL STYLES -------------------------------------------------- */ p.label { margin-top: 1em; } p.labelproc { margin-top: 1em; color: #000066; } /* -------------------------------------------------- GRAPHIC STYLES -------------------------------------------------- */ img { border: none; } /* -------------------------------------------------- LIST STYLES -------------------------------------------------- */ ol, ul { margin: .5em 0em 0em 2em; } li { margin-bottom: .5em; } ul p, ol p, dl p { margin-left: 0em; } ul p.label, ol p.label { margin-top: .5em; } /* -------------------------------------------------- DEFINITION LIST STYLES -------------------------------------------------- */ dl { margin-top: 0em; padding-left: 1px; /* Prevents italic-letter descenders from being cut off */ } dd { margin-bottom: 0em; margin-left: 1.5em; } dt { margin-top: .5em; } /* -------------------------------------------------- CODE, SYNTAX, and REFTIP STYLES -------------------------------------------------- */ pre { margin-top: .5em; margin-bottom: .5em; } pre, code, .code { font: 100% 瀹嬩綋, Courier New, Monospace, Courier;/* This is 100% of 70% */ color: #000066; } pre b, code b { letter-spacing: .1em; /* opens kerning on bold in Syntax/Code */ } pre.syntax { font: 100% Courier New, 瀹嬩綋, Monospace, Courier;/* This is 100% of 70% */ background: #cccccc; padding: 4px 8px; cursor: text; margin-top: 1em; margin-bottom: 1em; color: #000000; border-width: 1px; border-style: solid; border-color: #999999; } /* -------------------------------------------------- LINK STYLES -------------------------------------------------- */ a:link { color: #0000ff; } a:visited { color: #0000ff; } a:hover { color: #3366ff; } /* --------------------------- MSHelp\:link - Help HxLinks --------------------------- */ MSHelp\:link { text-decoration: underline; color: #0000ff; hoverColor: #3366ff; filterString: ; } A.HxLinkTable /* MSHelp\:link - Table disambiguation elements */ { } /* --------------------------- MSHelp\:ktable - Help links --------------------------- */ MSHelp\:ktable { disambiguator: span; separator: &nbsp|&#32; prefix: |&#32; postfix: &nbsp; filterString: ; } div.HxLinkTable { width: auto; /* Forces tables to have correct right margins and top spacing */ margin-top: -.4em; visibility: visible; } ol div.HxLinkTable, ul div.HxLinkTable { margin-top: 0em; /* Forces tables to have correct right margins and top spacing */ } table.HxLinkTable /* Keep in sync with general table settings below */ { width: auto; margin-top: 1.5em; margin-bottom: .3em; margin-left: -1em; border-width: 1px 1px 0px 0px; border-style: solid; border-color: #999999; background-color: #999999; font-size: 100%; /* Text in Table is same size as text outside table */ behavior:url(hxlinktable.htc); /* Attach the behavior to link elements. */ } table.HxLinkTable th, table.HxLinkTable td /* Keep in sync with general table settings below */ { border-style: solid; /* Creates the cell border and color */ border-width: 0px 0px 1px 1px; border-style: solid; border-color: #999999; padding: 4px 6px; text-align: left; } table.HxLinkTable th /* Keep in sync with general table settings below */ { background: #cccccc; /* Creates the shaded table header row */ vertical-align: bottom; } table.HxLinkTable td /* Keep in sync with general table settings below */ { background: #ffffff; vertical-align: top; } /* -------------------------------------------------- TABLE STYLES -------------------------------------------------- */ div.tablediv { width: 100%; /* Forces tables to have correct right margins and top spacing */ margin-top: -.4em; } ol div.tablediv, ul div.tablediv, ol div.HxLinkTable, ul div.HxLinkTable { margin-top: 0em; /* Forces tables to have correct right margins and top spacing */ } table.dtTABLE { width: 100%; /* Forces tables to have correct right margin */ margin-top: .6em; margin-bottom: .3em; border-width: 1px 1px 0px 0px; border-style: solid; border-color: #999999; background-color: #999999; font-size: 100%; /* Text in Table is same size as text outside table */ } table.dtTABLE th, table.dtTABLE td { border-style: solid; /* Creates the cell border and color */ border-width: 0px 0px 1px 1px; border-style: solid; border-color: #999999; padding: 4px 6px; text-align: left; } table.dtTABLE th { background: #cccccc; /* Creates the shaded table header row */ vertical-align: bottom; } table.dtTABLE td { background: #ffffff; vertical-align: top; } /* -------------------------------------------------- ISSUE REPORTING AND MISC LINKS TOPIC FOOTER -------------------------------------------------- */ div.footer { } div.footer hr { color: #999999; height: 1px; } /* -------------------------------------------------- STYLES FOR RUNNING HEADS -------------------------------------------------- */ table.bannerparthead, table.bannertitle /* General values for the Running Head tables */ { position: relative; left: 0px; top: 0px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px; width: 100%; height: 21px; border-collapse: collapse; border-style: solid; border-width: 0px; background-color: #99ccff; font-size: 100%; } table.bannerparthead td /* General Values for cells in the top row of running head */ { margin: 0px 0px 0px 0px; padding: 2px 0px 0px 4px; vertical-align: middle; /*border-width: 0px 0px 1px 0px; */ border-width: 0px border-style: solid; border-color: #999999; background: transparent; /* font-style: normal; */ font-weight: normal; } table.bannerparthead td.product /* Values for top right cell in running head */ { /* Allows for a second text block in the running head */ text-align: right; padding: 2px 5px 0px 5px; } table.bannertitle td /* General Values for cells in the bottom row of running head */ { margin: 0px 0px 0px 0px; padding: 0px 0px 0px 3px; vertical-align: middle; border-width: 0px 0px 1px 0px; border-style: solid; border-color: #999999; background: transparent; font-weight: bold; } td.button1 /* Values for button cells */ { width: 14px; cursor: hand; } /* ================================================= STYLES REQUIRED BY THE SCRIPT */ /* -------------------------------------------------- SAMPLE VIEWER -------------------------------------------------- */ div#smpMgrCell { display:none; } table.SampMgr { margin: 0px 0px 0px -22px; } table.SampMgr td { padding-left: 22px; } /* -------------------------------------------------- RUNNING HEAD BAR POPUP STYLES: See Also, Requirements, MultiLang Filtering -------------------------------------------------- */ div.sapop, div.langMenu /* See Also & Requirements popups */ { position: absolute; left: 0px; z-index: 1; width: 50%; padding: 0px 8px 5px 26px; visibility: hidden; border: 1px solid #999999; /* Same as all other border colors */ background: #ffffcc; } div.langMenu /* MultiLang Filter popup */ { padding: 10px 10px 10px 10px; } div.langMenu ul { list-style-type: none; padding-left: 5px; margin-left: 0px; } .lang, .ilang /* controls the multilang tag styles */ { color: #333333; font-family: Verdana, Arial, 瀹嬩綋, Helvetica, sans-serif; font-size: 80%; font-weight: normal; font-style: normal; } h1 .lang, h1 .ilang { font-size: 80%; } div.filtered { margin-top: .6em; margin-bottom: .6em; margin-left: -7px; padding: 0px 0px 0px 6px; border-left: 1px solid #999999; background: #ffffff; } div.filtered h1, div.filtered h2, div.filtered h3, div.filtered h4 { margin-left: -22px; } div.filtered span.lang { position: relative; left: 0px; } /* -------------------------------------------------- PARAMETER POPUP STYLES -------------------------------------------------- */ div.reftip /* Defines the RefTip popup in Syntax */ { position: absolute; z-index: 1; visibility: hidden; border: 1px solid #999999; background: #ffffcc; /* padding: 0px 0px 0px 0px; */ } div.reftip dl /* Sets margin around the text within the popup */ { margin: 3px 8px 8px 8px; } a.synParam /* parameter popup links */ { color: #0000ff; /* Must match the a:link style color */ text-decoration: underline; } a.synParam:visited /* ensures parameter popup links are always the unvisited color */ { color: #0000ff; /* Must match the a:link style color */ text-decoration: underline; } a.synParam:hover /* parameter popup links */ { color: #3366ff; /* Must match the a:hover style color */ text-decoration: underline; font-style: italic; } /* -------------------------------------------------- EXPAND-COLLAPSE STYLES -------------------------------------------------- */ div.expandBody { margin: .5em 0em 0em 1.4em; display:none; } a.expandLink1 { font-size: 115%; } a#ExPand { color: #3366ff; font-weight: bold; text-decoration: none; } a#ExPandAll { color: #3366ff; font-weight: bold; text-decoration: none; } /* -------------------------------------------------- GLOSSARY POPUP STYLES Not used by Visual Studio .NET -------------------------------------------------- */ /* COMMENT OUT GLOSSARY SECTION /*div#popUpWindow { Controlled by the script in the variable L_PopUpBoxStyle_Style }*/ a.glosslink:link { color: #000000; } a.glosslink:visited { color: #000000; } a.glosslink:hover { color: #000000; font-style: italic; } div#popUpWindow h5 /* Controls the style of the Term in Glossary Popups */ { margin: 5px 5px 5px 5px; color: #000000; } div#popUpWindow p /* Controls the style of the Text in Glossary Popups */ { margin: 5px 5px 5px 5px; color: #000000; } p.GLOSSARY_TEXT { } div#popUpWindow a /* Controls the style of the Links in Glossary Popups */ { } */ /* END COMMENT OUT OF GLOSSARY SECTION */ /* END STYLES REQUIRED BY THE SCRIPT ================================================== */ </style> <HEAD> <META HTTP-EQUIV="Content-Type" Content="text/html; charset=gb2312"> <TITLE>定位点</TITLE> <xml> <MSHelp:TOCTitle <HR><!--Feedback Link--> <p><A HREF="JavaScript:sendfeedback('CHS _731809', 'VSDOCS@MICROSOFT.COM')">将文档反馈发送给 Microsoft</A></p><!--Copyright--> <p><MSHelp:link keywords="vxmscCopyright" TABINDEX="0">&copy; 2002 Microsoft Corporation。保留所有权利。</MSHelp:link></p></div> <!--Closes the footer div--> </div> <!--closes the topic content div--> <!--FOOTER_END--> </BODY> </HTML>


替换和分组
说明替换如何使用[|]字符,以在两个或更多替换选项之间选择,并说明分组如何与替换协同作用以进一步精炼结果。

替换使用 | 字符来允许在两个或多个替换选项之间进行选择。例如,可以扩展章节标题正则表达式,以返回比章标题范围更广的匹配项。但是,这并不象您可能认为的那样简单。替换匹配 | 字符两边的尽可能最大的表达式。您可能认为,下面的表达式匹配出现在行首和行尾、后面跟一个或两个数字的 Chapter 或 Section:

/^Chapter|Section [1-9][0-9]{0,1}$/
很遗憾,上面的正则表达式要么匹配行首的单词 Chapter,要么匹配行尾的单词 Section 及跟在其后的任何数字。如果输入字符串是 Chapter 22,那么上面的表达式只匹配单词 Chapter。如果输入字符串是 Section 22,那么该表达式匹配 Section 22。

若要使正则表达式更易于控制,可以使用括号来限制替换的范围,即,确保它只应用于两个单词 Chapter 和 Section。但是,括号也用于创建子表达式,并可能捕获它们以供以后使用,这一点在有关反向引用的那一节讲述。通过在上面的正则表达式的适当位置添加括号,就可以使该正则表达式匹配 Chapter 1 或 Section 3。

下面的正则表达式使用括号来组合 Chapter 和 Section,以便表达式正确地起作用:

/^(Chapter|Section) [1-9][0-9]{0,1}$/
尽管这些表达式正确地起作用,但 Chapter|Section 两侧的括号也引起两个匹配单词之一被捕获以供未来使用。由于在上面的表达式中只有一组括号,因此,只有一个被捕获的[子匹配项]。可以通过使用 RegExp 对象的 $1-$9 属性来引用此子匹配项。

在上面的示例中,您只需要使用括号来组合单词 Chapter 和 Section 之间的选择。若要防止匹配被保存以备将来使用,请在括号内正则表达式模式之前放置 ?:。下面的修改提供相同的能力而不保存子匹配项:

/^(?:Chapter|Section) [1-9][0-9]{0,1}$/
除 ?: 元字符外,两个其他非捕获元字符创建被称为[预测先行]匹配的某些内容。正向预测先行使用 ?= 指定,它匹配处于括号中匹配正则表达式模式的起始点的搜索字符串。反向预测先行使用 ?! 指定,它匹配处于与正则表达式模式不匹配的字符串的起始点的搜索字符串。

例如,假设您有一个文档,该文档包含指向 Windows 3.1、Windows 95、Windows 98 和 Windows NT 的引用。再进一步假设,您需要更新该文档,将指向 Windows 95、Windows 98 和 Windows NT 的所有引用更改为 Windows 2000。下面的正则表达式(这是一个正向预测先行的示例)匹配 Windows 95、Windows 98 和 Windows NT:

/Windows(?=95 |98 |NT )/
找到一处匹配后,紧接着就在匹配的文本(不包括预测先行中的字符)之后搜索下一处匹配。例如,如果上面的表达式匹配 Windows 98,将在 Windows 之后而不是在 98 之后继续搜索。
反向引用
说明如何创建可以访问存储匹配模式的组成部分的正则表达式,而不必重新创建构成这一匹配模式的正则表达式。



正则表达式的最重要功能之一是存储匹配的模式的一部分以供以后重新使用的能力。您可能想起,若在正则表达式模式或模式的一部分两侧加上括号,就会导致表达式的一部分被存储到临时缓冲区中。可以通过使用非捕获元字符 ?:、?= 或 ?! 来重写捕获。

每个捕获的子匹配项按照它们在正则表达式模式中从左到右出现的顺序存储。缓冲区编号从 1 开始,最多可存储 99 个捕获的子表达式。可以使用 \n 来访问每个缓冲区,其中 n 是标识特定缓冲区的一位或两位十进制数字。

反向引用的最简单的、最有用的应用之一,是提供查找文本中两个相同的相邻单词的匹配项的能力。以下面的句子为例:

Is is the cost of of gasoline going up up?
上面的句子很显然有多个重复的单词。如果能设计一种方法定位该句子,而不必查找每个单词的重复出现,那该有多好。下面的正则表达式使用单个子表达式来实现这一点:

/\b([a-z]+) \1\b/gi
捕获的表达式,正如 [a-z]+ 指定的,包括一个或多个字母。正则表达式的第二部分是对以前捕获的子匹配项的引用,即,单词的第二个匹配项正好由括号表达式匹配。\1 指定第一个子匹配项。字边界元字符确保只检测整个单词。否则,诸如[is issued]或[this is]之类的词组将不能正确地被此表达式识别。

正则表达式后面的全局标记 (g) 指示,将该表达式应用到输入字符串中能够查找到的尽可能多的匹配。表达式的结尾处的不区分大小写 (i) 标记指定不区分大小写。多行标记指定换行符的两边可能出现潜在的匹配。

使用上面的正则表达式,下面的代码可以使用子匹配项信息,将文本字符串中的两个连续相同的单词的匹配项替换为同一单词的单个匹配项:

var ss = "Is is the cost of of gasoline going up up?.\n";
var re = /\b([a-z]+) \1\b/gim;       //Create regular expression pattern.
var rv = ss.replace(re,"$1");   //Replace two occurrences with one.
在 replace 方法内使用 $1 引用第一个保存的子匹配项。如果您有多个子匹配项,您将通过使用 $2、$3 等依次引用它们。

反向引用还可以将通用资源指示符 (URI) 分解为其组件。假定您想将下面的 URI 分解为协议(ftp、http 等等)、域地址和页/路径:

http://msdn.microsoft.com:80/scripting/default.htm
下面的正则表达式提供该功能:

/(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)/
第一个括号子表达式捕获 Web 地址的协议部分。该子表达式匹配在冒号和两个正斜杠前面的任何单词。第二个括号子表达式捕获地址的域地址部分。该子表达式匹配不包括 ^、/ 或 : 字符的任何字符序列。第三个括号子表达式捕获端口号(如果指定了的话)。该子表达式匹配冒号后面的零个或多个数字。最后,第四个括号子表达式捕获 Web 地址指定的路径和/或页信息。该子表达式匹配 # 或空格字符之外的一个或多个字符。

将正则表达式应用到上面的 URI,各子匹配项包含下面的内容:

RegExp.$1 包含[http]
RegExp.$2 包含[msdn.microsoft.com]
RegExp.$3 包含[:80]
RegExp.$4 包含[/scripting/default.htm]

正则入门 到此结速 后续为   深入正则表达式编程
出版日期 还未确定........

查看更多关于正则入门连载!(献给不及格的程序员们)的详细内容...

  阅读:44次