﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-QingFeng-文章分类-Java小记</title><link>http://www.cnitblog.com/Qing-Feng/category/3530.html</link><description>青草可以无语，山峰可以无言，青峰岂能无情、无义</description><language>zh-cn</language><lastBuildDate>Wed, 05 Oct 2011 06:54:31 GMT</lastBuildDate><pubDate>Wed, 05 Oct 2011 06:54:31 GMT</pubDate><ttl>60</ttl><item><title>正则表达式详解（三）--正则表达式练习器</title><link>http://www.cnitblog.com/Qing-Feng/articles/15627.html</link><dc:creator>【青峰小寨】</dc:creator><author>【青峰小寨】</author><pubDate>Sun, 20 Aug 2006 15:55:00 GMT</pubDate><guid>http://www.cnitblog.com/Qing-Feng/articles/15627.html</guid><wfw:comment>http://www.cnitblog.com/Qing-Feng/comments/15627.html</wfw:comment><comments>http://www.cnitblog.com/Qing-Feng/articles/15627.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/Qing-Feng/comments/commentRss/15627.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/Qing-Feng/services/trackbacks/15627.html</trackback:ping><description><![CDATA[
		<p>
				<font color="#9acd32">
						<font color="#000000">　　以下是用JAVASCRIPT+HTML写的一个正则表达式的练习器，帮助大家共同学习正则表达式，以下代码可能存在BUG，比如正则表达式的判断没有做异常处理，这还需要大家的共同改进，谢谢指点！</font>
						<br />
						<br />&lt;!-----------------------------------------------------------------<br />// 档案名称：RegExp.htm<br />// 原创作者：青峰<br />// 作者邮件：</font>
				<a href="mailto:150343747@qq.com">
						<font color="#9acd32">150343747@qq.com</font>
				</a>
				<br />
				<font color="#9acd32">// 创建日期：星期三，2006年08月09日 17:50:42<br />// 版权所有(C)青峰工作室<br />//----------------------------------------------------------------&gt;</font>
		</p>
		<p>
				<font color="#9acd32">&lt;HTML&gt;<br />&lt;HEAD&gt;<br /> &lt;Title&gt;正则表达式练习器&lt;/Title&gt;<br /> &lt;META http-equiv="Content-Type" content="text/html; charset=gb2312"&gt;<br /> &lt;script language="JavaScript"&gt;<br /> function OnMove() <br /> {<br />  window.status = "("+window.event.clientX+","+window.event.clientY+")" + " :: "+document.location;<br /> }<br /> &lt;/script&gt;</font>
		</p>
		<p>
				<font color="#9acd32"> &lt;SCRIPT LANGUAGE="JavaScript1.2"&gt;<br />  var re = new RegExp(); //建立正则表达式对象<br />  var nextpoint = 0; //匹配时的偏移量<br />  //设置正则表达式<br />  function setPattern(form)<br />  {<br />   var mode;<br />   if(form.chkmode.checked)<br />    mode = "gi"; //i:不分大小写 g:全局，好象没什么作用<br />   else <br />    mode = "g";<br />   re.compile(form.regexp.value,mode);<br />   nextpoint = 0;<br />   form.reglist.value = "";<br />  }<br />  <br />  //检查是否有匹配<br />  function findIt(form) <br />  {<br />   setPattern(form);<br />   var input = form.main.value;<br />   if (input.search(re) != -1)<br />   {<br />    form.output[0].checked = true; <br />   } <br />   else <br />   {<br />    form.output[1].checked = true; <br />   }<br />  }<br />  <br />  //检查匹配位置<br />  function locateIt(form)<br />  {<br />   setPattern(form);<br />   var input = form.main.value;<br />   form.offset.value = input.search(re);<br />  }<br />  <br />  //检查所有的匹配情况<br />  function execIt(form) <br />  {<br />   if(nextpoint == 0 || ! form.scankmode.checked) <br />   {<br />    findIt(form);<br />    form.reglist.value = "";<br />   }<br />  <br />   var key = true;<br />   if(form.scankmode.checked) <br />    key = false;<br />   do <br />   {<br />    var input = form.main.value;<br />    var matchArray = re.exec(input.substr(nextpoint));<br />    if(matchArray)<br />    {<br />     for(var i=1;i&lt;matchArray.length;i++)<br />      matchArray[i] = "$"+i+":"+matchArray[i];<br />     form.reglist.value = (nextpoint+matchArray.index)+" =&gt; " + matchArray[0] +"\n"+form.reglist.value;<br />     form.matchlist.value = "$0:"+matchArray.join("\n");<br />     nextpoint = nextpoint + matchArray.index + matchArray[0].length;<br />    }<br />    else <br />    {<br />     if(!key)<br />      form.reglist.value = "没有找到\n" + form.reglist.value; <br />     form.matchlist.value = " ";<br />     nextpoint = 0;<br />     key = false;<br />    }<br />   }while (key)<br />  }<br />  //设置当前使用的正则表达式<br />  function setregexp(n) {<br />   var s = document.all.regexplist.value.split("\r\n");<br />   document.all.regexp.value = s[n*2-1]; //.replace("\r","")<br />   nextpoint = 0;<br />  }</font>
		</p>
		<p>
				<font color="#9acd32">  //定义选择监视<br />  var isNav = (navigator.appName == "Netscape");<br />  function showSelection() <br />  {<br />   if (isNav)<br />   {<br />    var theText = document.getSelection();<br />   } <br />   else <br />   {<br />    var theText = document.selection.createRange().text;<br />   }<br />   if(theText.length&gt;0 &amp;&amp; document.all.selechkmode.checked)<br />    document.all.regexp.value = theText;<br />  }<br />  if (isNav) <br />  {<br />   document.captureEvents(Event.MOUSEUP)<br />  }<br />  document.onmouseup = showSelection<br />&lt;/SCRIPT&gt;</font>
		</p>
		<p>
				<font color="#9acd32">&lt;/HEAD&gt;<br />&lt;BODY style="font-size=9pt;" OnMouseMove=OnMove()&gt;<br /> &lt;FORM&gt;<br />  &lt;table width=100% cellspacing=0 cellpadding=0&gt;<br />   &lt;tr&gt;<br />    &lt;td&gt;&lt;font color=red&gt;正规表达式练习器&lt;/font&gt;&lt;/td&gt;<br />    &lt;td align=right&gt;&lt;a href=mailto:150343747@qq.com&gt;150343747@qq.com&lt;/a&gt;&lt;/td&gt;<br />   &lt;/tr&gt;<br />  &lt;/table&gt;<br />  &lt;table width=100% broder=1 frame=above rules=none style="font-size:9pt;"&gt;<br />   &lt;tr&gt;<br />    &lt;td width=50% valign=top&gt;<br />     输入一些被寻找的正文:&lt;BR&gt;<br />     &lt;TEXTAREA NAME="main" COLS=58 ROWS=5 WRAP="virtual" style="font-size:9pt;"&gt;08-09-2006 08/09/2006 150343747@qq.com 12345 196.168.1.1 www.sohu.com ftp://www.china.com 2001.9.11 http://www.wwwjj.com.cn/club/bbs/bbsView.asp http://www.163.com/inden.htm<br">http://www.163.com/inden.htm&lt;/TEXTAREA&gt;&lt;BR&gt;<br />     进行匹配的正规表达式:　　忽略大小写<br />     &lt;INPUT TYPE="checkbox" NAME="chkmode" checked style="font-size:8pt;height:18px"&gt;&lt;BR&gt;<br />     &lt;TEXTAREA NAME="regexp" COLS=51 ROWS=5 style="font-size:9pt;"&gt;&lt;/TEXTAREA&gt;<br />     &lt;INPUT TYPE="button" VALUE="清除" onClick="this.form.regexp.value=''" style="font-size:8pt;height:18px"&gt;&lt;BR&gt;<br />     &lt;INPUT TYPE="button" VALUE="能找到吗?[regexObject.test(string)]" style="font-size:8pt;width:70%;height:18px" onClick="findIt(this.form)"&gt;<br />     &lt;INPUT TYPE="radio" NAME="output" style="font-size:8pt;height:18px"&gt;Yes<br />     &lt;INPUT TYPE="radio" NAME="output" style="font-size:8pt;height:18px"&gt;No &lt;BR&gt;<br />     &lt;INPUT TYPE="button" VALUE="在哪里?[string.search(regexObject)]" style="font-size:8pt;width:70%;height:18px" onClick="locateIt(this.form)"&gt;<br />     &lt;INPUT TYPE="text" NAME="offset" SIZE=4 style="font-size:8pt;height:18px"&gt;<br />    &lt;/td&gt;<br />    &lt;td valign=top&gt;<br />     测试用正则表达式列表:　使用第<br />     &lt;input type=text name=num size=2 value=1 style="font-size:8pt;height:18px"&gt;个<br />     &lt;input type=button value=Go onClick=setregexp(this.form.num.value) style="font-size:8pt;height:18px"&gt;允许复制<br />     &lt;INPUT TYPE="checkbox" NAME="selechkmode" style="font-size:8pt;height:18px"&gt;<br />     &lt;textarea NAME="regexplist" cols=58 rows=14 wrap=off style="font-size:9pt;"&gt;1.检查日期:<br />([0-1]?[1-9])[-./](0?[1-9]|[12][0-9]|3[01])[-./](\d\d\d\d)<br />2.检查数字:<br />([-+]?[0-9]+\.?[0-9]+)<br />3.检查URL:<br />((http|ftp)://)?(((([\d]+\.)+){3}[\d]+(/[\w./]+)?)|([a-z]\w*((\.\w+)+){2,})([/][\w.~]*)*)<br />4.检查E-mail:<br />\w+@((\w+[.]?)+)<br />     &lt;/textarea&gt;<br />    &lt;/td&gt;<br />   &lt;/tr&gt;<br />   &lt;tr&gt;<br />    &lt;td valign=bottom&gt;<br />     &lt;INPUT TYPE="button" VALUE="有哪些?[regexObject.exec(string)]" style="font-size:8pt;width:70%;height:18px" onClick="execIt(this.form)"&gt;单步<br />     &lt;INPUT TYPE="checkbox" NAME="scankmode" style="font-size:8pt;height:18px"&gt;&lt;BR&gt;<br />     &lt;TEXTAREA NAME="reglist" COLS=58 ROWS=8 style="font-size:9pt;"&gt;&lt;/TEXTAREA&gt;<br />    &lt;/td&gt;<br />    &lt;td valign=bottom&gt;<br />     匹配到的成分:(单步时可见)<br />     &lt;TEXTAREA NAME="matchlist" COLS=58 ROWS=8 style="font-size:9pt;"&gt;&lt;/TEXTAREA&gt;<br />    &lt;/td&gt;<br />   &lt;/tr&gt;<br />  &lt;/table&gt;<br /> &lt;/FORM&gt;<br /> &lt;script&gt;<br />  setregexp(1)<br /> &lt;/script&gt;<br />&lt;/BODY&gt;<br />&lt;/HTML&gt;</br"></font>
		</p>
<img src ="http://www.cnitblog.com/Qing-Feng/aggbug/15627.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/Qing-Feng/" target="_blank">【青峰小寨】</a> 2006-08-20 23:55 <a href="http://www.cnitblog.com/Qing-Feng/articles/15627.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>正则表达式详解（二）--在JavaScript中的应用</title><link>http://www.cnitblog.com/Qing-Feng/articles/15624.html</link><dc:creator>【青峰小寨】</dc:creator><author>【青峰小寨】</author><pubDate>Sun, 20 Aug 2006 13:17:00 GMT</pubDate><guid>http://www.cnitblog.com/Qing-Feng/articles/15624.html</guid><wfw:comment>http://www.cnitblog.com/Qing-Feng/comments/15624.html</wfw:comment><comments>http://www.cnitblog.com/Qing-Feng/articles/15624.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/Qing-Feng/comments/commentRss/15624.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/Qing-Feng/services/trackbacks/15624.html</trackback:ping><description><![CDATA[
		<p>　　这段时间项目上都流行起AJAX，而JavaScript就成为了AJAX的核心部分。以前只是用JavaScript实现一下页面的特效而已，而现在使用起来发现它的功能而不小。好了，还是讲今天的正题吧，关于AJAX我肯定会单独发时间和发篇幅来描述它的。<br />　　在前面我已经讲述了关于正则表达式的概念和基本语法，现在就研究一下正则表达式在JavaScript中应用。<br /><br /><strong>使用RegExp对象执行字符串模式匹配</strong><br />　　RegExp是JavaScript中的正则表达式对象，利用它可以完成字符串匹配的各种操作。获得一个RegExp对象可以用两种方式：<br />　　<font color="#008000"><font color="#0000ff">var </font></font>objRegExp = /pattern*/[flag]<br />　　<font color="#0000ff"><font color="#008000">//或者</font><br /></font>　　<font color="#0000ff">var</font> objRegExp = <font color="#0000ff">new</font><font color="#0000ff">RegExp</font>("pattern" [, "flag"]);<br />　　其中pattern是要匹配的模式，flag表示搜索模式，有两个可选参数，分别是g和i。g表示全局搜索，在后面介绍的replace方法中非常有用；i表示忽略大小写，默认情况下是大小写敏感的。<br />　　例如：<br />　　/jimek/ig<br />　　<font color="#0000ff">new</font> RegExp("jimek","ig");<br />　　都表示全局匹配文本中的"jimek"单词，并且忽略大小写。<br />①    RegExp的方法（如下表）<br /></p>
		<table class="MsoNormalTable" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; MARGIN: auto auto auto 5.4pt; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellspacing="0" cellpadding="0" align="center" border="1">
				<tbody>
						<tr style="HEIGHT: 19.9pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes">
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 420.7pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 19.9pt; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt" width="561" colspan="2">
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center; mso-pagination: widow-orphan" align="center">
												<b style="mso-bidi-font-weight: normal">
														<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">表</span>
												</b>
												<b style="mso-bidi-font-weight: normal">
														<span lang="EN-US" style="FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
																<span style="mso-spacerun: yes">   </span>
														</span>
												</b>
												<b style="mso-bidi-font-weight: normal">
														<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">正则表达式对象</span>
												</b>
												<b style="mso-bidi-font-weight: normal">
														<span lang="EN-US" style="FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">RegExp</span>
												</b>
												<b style="mso-bidi-font-weight: normal">
														<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">的方法</span>
												</b>
												<b style="mso-bidi-font-weight: normal">
														<span lang="EN-US" style="FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">
																<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?>
																<o:p>
																</o:p>
														</span>
												</b>
										</p>
								</td>
						</tr>
						<tr style="mso-yfti-irow: 1">
								<td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 126.3pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" width="168">
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center; mso-pagination: widow-orphan; tab-stops: list 18.0pt" align="center">
												<b style="mso-bidi-font-weight: normal">
														<span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">方<span lang="EN-US"><span style="mso-spacerun: yes">  </span></span>法<span lang="EN-US"><o:p></o:p></span></span>
												</b>
										</p>
								</td>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 294.4pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" width="393">
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center; mso-pagination: widow-orphan; tab-stops: list 18.0pt" align="center">
												<b style="mso-bidi-font-weight: normal">
														<span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">描<span lang="EN-US"><span style="mso-spacerun: yes">  </span></span>述<span lang="EN-US"><o:p></o:p></span></span>
												</b>
										</p>
								</td>
						</tr>
						<tr style="mso-yfti-irow: 2">
								<td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 126.3pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" width="168">
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm">
												<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">compile(pattern,flags)<o:p></o:p></span>
										</p>
								</td>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 294.4pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="top" width="393">
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm">
												<span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">将正则表达式转换为内部格式，对于批量匹配可以提高匹配效率</span>
												<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt; mso-fareast-font-family: 'Times New Roman'">
														<o:p>
														</o:p>
												</span>
										</p>
								</td>
						</tr>
						<tr style="mso-yfti-irow: 3">
								<td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 126.3pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" width="168">
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm">
												<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">exec(str)<o:p></o:p></span>
										</p>
								</td>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 294.4pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="top" width="393">
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm">
												<span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">按照<span lang="EN-US">RegExp</span>对象的匹配模式对<span lang="EN-US">str</span>字符串进行匹配查找，当设定了全局搜索模式（<span lang="EN-US">g</span>），则匹配查找从<span lang="EN-US">RegExp</span>对象<span lang="EN-US">lastIndex</span>属性指定的目标字符串位置开始；若没有设置全局搜索，则从目标字符串第一个字符开始搜索。若没有任何匹配发生，返回<span lang="EN-US">null</span>。<span lang="EN-US"><o:p></o:p></span></span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm">
												<span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">该方法将匹配结果放在一个数组内返回，该数组由<span lang="EN-US">3</span>个属性：<span lang="EN-US"><o:p></o:p></span></span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm">
												<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">input</span>
												<span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">：包含目标字符串，同<span lang="EN-US">RegExp.index<o:p></o:p></span></span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm">
												<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">index</span>
												<span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">：匹配到的子字符串在目标子字符串中的位置，同<span lang="EN-US">RegExp.index<o:p></o:p></span></span>
										</p>
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm">
												<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">lastIndex</span>
												<span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">：匹配到的子字符串后面一个字符的位置，同<span lang="EN-US">RegExp.lastIndex<o:p></o:p></span></span>
										</p>
								</td>
						</tr>
						<tr style="mso-yfti-irow: 4; mso-yfti-lastrow: yes">
								<td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 126.3pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" width="168">
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm">
												<span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">test(str)<o:p></o:p></span>
										</p>
								</td>
								<td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 294.4pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="top" width="393">
										<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm">
												<span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">判断<span lang="EN-US">str</span>是否符合指定的模式，返回一个布尔变量，<span lang="EN-US">true</span>或者<span lang="EN-US">false</span>，需要注意，这个方法不会改变<span lang="EN-US">RegExp</span>的属性值<span lang="EN-US"><o:p></o:p></span></span>
										</p>
								</td>
						</tr>
				</tbody>
		</table>　　在执行完字符串匹配后，匹配结果会以RegExp静态属性的方式提供给脚本程序，每次执行exec都会改变这些静态属性。<br />②    RegExp的静态属性<br /><table class="MsoNormalTable" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; MARGIN: auto auto auto 5.4pt; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" cellspacing="0" cellpadding="0" align="center" border="1"><tbody><tr style="HEIGHT: 19.9pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes"><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 420.7pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 19.9pt; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt" width="561" colspan="2"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center; mso-pagination: widow-orphan" align="center"><b style="mso-bidi-font-weight: normal"><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">表</span></b><b style="mso-bidi-font-weight: normal"><span lang="EN-US" style="FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><span style="mso-spacerun: yes">   </span></span></b><b style="mso-bidi-font-weight: normal"><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">正则表达式对象</span></b><b style="mso-bidi-font-weight: normal"><span lang="EN-US" style="FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">RegExp</span></b><b style="mso-bidi-font-weight: normal"><span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">的静态属性</span></b><b style="mso-bidi-font-weight: normal"><span lang="EN-US" style="FONT-SIZE: 12pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"><o:p></o:p></span></b></p></td></tr><tr style="mso-yfti-irow: 1"><td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 126.3pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" width="168"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center; mso-pagination: widow-orphan; tab-stops: list 18.0pt" align="center"><b style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">静<span lang="EN-US"><span style="mso-spacerun: yes">  </span></span>态<span lang="EN-US"><span style="mso-spacerun: yes">  </span></span>属<span lang="EN-US"><span style="mso-spacerun: yes">  </span></span>性<span lang="EN-US"><o:p></o:p></span></span></b></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 294.4pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" width="393"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: center; mso-pagination: widow-orphan; tab-stops: list 18.0pt" align="center"><b style="mso-bidi-font-weight: normal"><span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">描<span lang="EN-US"><span style="mso-spacerun: yes">  </span></span>述<span lang="EN-US"><o:p></o:p></span></span></b></p></td></tr><tr style="mso-yfti-irow: 2"><td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 126.3pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" width="168"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm"><span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">RegExp.input<o:p></o:p></span></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 294.4pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="top" width="393"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm"><span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">保存被搜索的字符串</span><span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt; mso-fareast-font-family: 'Times New Roman'"><o:p></o:p></span></p></td></tr><tr style="mso-yfti-irow: 3"><td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 126.3pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" width="168"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm"><span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">RegExp.index<o:p></o:p></span></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 294.4pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="top" width="393"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm"><span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">保存匹配的首字符的位置<span lang="EN-US"><o:p></o:p></span></span></p></td></tr><tr style="mso-yfti-irow: 4"><td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 126.3pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" width="168"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm"><span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">RegExp.lastIndex<o:p></o:p></span></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 294.4pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="top" width="393"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm"><span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">保存匹配的字符串下一个字符的位置<span lang="EN-US"><o:p></o:p></span></span></p></td></tr><tr style="mso-yfti-irow: 5"><td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 126.3pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" width="168"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm"><span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">RegExp.lastMatch<o:p></o:p></span></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 294.4pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="top" width="393"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm"><span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">保存匹配到的字符串<span lang="EN-US"><o:p></o:p></span></span></p></td></tr><tr style="mso-yfti-irow: 6"><td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 126.3pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" width="168"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm"><span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">RegExp.lastParen<o:p></o:p></span></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 294.4pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="top" width="393"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm"><span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">保存最后一个被匹配的字符串（最后一个括号的内容）<span lang="EN-US"><o:p></o:p></span></span></p></td></tr><tr style="mso-yfti-irow: 7"><td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 126.3pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" width="168"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm"><span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">RegExp.leftContext<o:p></o:p></span></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 294.4pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="top" width="393"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm"><span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">保存匹配字符串左边的内容<span lang="EN-US"><o:p></o:p></span></span></p></td></tr><tr style="mso-yfti-irow: 8"><td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 126.3pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" width="168"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm"><span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">RegExp.rightContext<o:p></o:p></span></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 294.4pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="top" width="393"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm"><span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">保存匹配字符串右边的内容<span lang="EN-US"><o:p></o:p></span></span></p></td></tr><tr style="mso-yfti-irow: 9; mso-yfti-lastrow: yes"><td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 126.3pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt" width="168"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm"><span lang="EN-US" style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">RegExp.$1</span><span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">～<span lang="EN-US">$9<o:p></o:p></span></span></p></td><td style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 5.4pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: #d4d0c8; WIDTH: 294.4pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="top" width="393"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan; tab-stops: list 0cm"><span style="FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt">保存最开始的<span lang="EN-US">9</span>个子匹配（括号中的内容）<span lang="EN-US"><o:p></o:p></span></span></p></td></tr></tbody></table>　　由此可见，所有的匹配结果都保存在同一个位置，当执行exec方法后，这些静态属性就会改变。因此，必须确保在执行完匹配后立即去使用匹配结果，或将它们保存到另外的变量中，而不再使用RegExp的这些属性。<br /><br /><strong>提取子字符串<br /></strong>　　在匹配模式中，可以用小括号将子模式括起来，以获取子匹配的内容，这些匹配的结果被存储在RegExp.$1<span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">～<font size="3">$9中。例如，对于xml片断：<br />　　&lt;author&gt;jimek&lt;/author&gt;<br />　　如果要使用正则表达式获取其中的作者：jimek，可以这样实现：<br />　　&lt;script language="JavaScript" type="text/javascript"&gt;<br />　　&lt;!--<br />　　   var strXml = "&lt;author&gt;jimek&lt;/author&gt;";<br />　　   var regExp = /&lt;author&gt;(\w*)&lt;/author&gt;/;<br />　　   regExp.exec(strXml);<br />　　   var author = RegExp.$1;<br />　　   alert(author);<br />　　//--&gt;<br />　　&lt;/script&gt;<br />　　当需要提取多个子模式时，可以使用RegExp.$1<span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">～<font size="3">$9依次获取得到的字符串。如果需要得到的子模式不只9个，也可以使用exec返回的数组来获取子字符串，返回数组的长度为子模式的个数加1，其中数组索引为0的元素表示被搜索的字符串，其后的元素依次对应于模式中的括号。例如上面的例子也可以用下面的代码实现：<br />　　&lt;script language="JavaScript" type="text/javascript"&gt;<br />　　&lt;!--<br />　　   var strXml = "&lt;author&gt;jimek&lt;/author&gt;";<br />　　   var regExp = /&lt;author&gt;(\w*)&lt;/author&gt;/;<br />　　   var arr = regExp.exec(strXml);<br />　　   var author = arr[1];<br />　　   alert(author);<br />　　//--&gt;<br />　　&lt;/script&gt;<br /><br /><strong>与字符串相关的操作<br /></strong>　　在字符串相关的操作时，有3个方法的参数需要用到正则表达式<span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"><font size="3">：<br />1.  string.search(regularExpression)<br />　　其中string是要处理的字符串，regularExpression是匹配模式。该方法在string中查找指定的模式，如果找到，则返回它的第一个字符的索引位置，否则返回-1。例如：<br />　　"&lt;author&gt;jimek&lt;/author&gt;".search(/jimek/);<br />　　显示结果为8。与indexOf()方法不同，该方法接收的是一个正则表达式，而indexOf只能接收一个字符串。但两者的行为是类似的。<br />2.  string.replace(regularExpression,replaceString)<br />　　其中regularExpression是要查找的模式，replaceString是要替换匹配模式的字符串。regularExpression也可以用普通字符串，但那样只能替换第一个出现的匹配，之后的匹配则被忽略。使用正则表达式后可以使用全局模式来实现整个替换。替换后原有字符串不发生变化，而是返回一个新的字符串。<br />　　例如：在实际开发中经常要删除一段文本中HTML标记，以获取纯文本，可以使用如下代码实现：<br />　　&lt;script language="JavaScript" type="text/javascript"&gt;<br />　　&lt;!--<br />　　   function stripTags(s){<br />　　      return s.replace(/&lt;\/?[^&gt;]+&gt;/ig, '');<br />　　   }<br /><br />　　   var str = stripTags("&lt;author&gt;jimek&lt;/author&gt;");<br />　　   alert(str);<br />　　//--&gt;<br />　　&lt;/script&gt;<br />　　这样，HTML标记后的文本又得到了“jimek”。<br />3.  string.match(regularExpression)<br />　　该方法根据regularExpression正则表达式模式查找字符串string中的匹配字符项，将结果以数组形式返回。该数组有3个属性值，与exec方法返回的数组属性相同。若没有任何匹配，返回null。<br /><font style="BACKGROUND-COLOR: #0000ff"><font style="BACKGROUND-COLOR: #deebef"><strong>注意：</strong>若regularExpression对象未设定全局匹配模式，则数组索引为0的元素就是匹配的整体内容，索引为1<span style="FONT-SIZE: 10.5pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">～</span>9的元素则包含了子匹配得到的字符。若设定了全局模式，则数组包含了搜索到的所有整体匹配项。</font><br /></font></font></span></font></span></font></span><img src ="http://www.cnitblog.com/Qing-Feng/aggbug/15624.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/Qing-Feng/" target="_blank">【青峰小寨】</a> 2006-08-20 21:17 <a href="http://www.cnitblog.com/Qing-Feng/articles/15624.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>正则表达式详解（一）--定义与基本语法</title><link>http://www.cnitblog.com/Qing-Feng/articles/14967.html</link><dc:creator>【青峰小寨】</dc:creator><author>【青峰小寨】</author><pubDate>Tue, 08 Aug 2006 15:03:00 GMT</pubDate><guid>http://www.cnitblog.com/Qing-Feng/articles/14967.html</guid><wfw:comment>http://www.cnitblog.com/Qing-Feng/comments/14967.html</wfw:comment><comments>http://www.cnitblog.com/Qing-Feng/articles/14967.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/Qing-Feng/comments/commentRss/14967.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/Qing-Feng/services/trackbacks/14967.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 什么是正则表达式？　　这也是很多人面对新的事物首先提出的问题。同样，我也带着这种疑问认识和理解它。在百度里搜索“正则表达式”的结果真是琳琅满目，层出不穷。比如“微软正则表达式教程（一至五）”，这个大家可以去详细查看，以及想了解它的历史的可以查看《揭开正则表达式语法的神秘面纱》.很多人因为它们看上去比较古怪而且复杂所以不敢去使用——很不幸，这篇文章也不能够改变这一点，然而它的古怪它的复杂都是你的知觉...&nbsp;&nbsp;<a href='http://www.cnitblog.com/Qing-Feng/articles/14967.html'>阅读全文</a><img src ="http://www.cnitblog.com/Qing-Feng/aggbug/14967.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/Qing-Feng/" target="_blank">【青峰小寨】</a> 2006-08-08 23:03 <a href="http://www.cnitblog.com/Qing-Feng/articles/14967.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>