<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[静怡家园]]></title> 
<link>http://www.zhanghaijun.com/index.php</link> 
<description><![CDATA[书山有路勤为径，学海无涯苦作舟！]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[静怡家园]]></copyright>
<item>
<link>http://www.zhanghaijun.com/post//</link>
<title><![CDATA[ASP中正则表达式的应用-2]]></title> 
<author>碟舞飞扬 &lt;webmaster@zhanghaijun.com&gt;</author>
<category><![CDATA[Web开发]]></category>
<pubDate>Sun, 24 Jun 2007 17:52:49 +0000</pubDate> 
<guid>http://www.zhanghaijun.com/post//</guid> 
<description>
<![CDATA[ 
	三、JavaScript中正则表达式的使用 <br/>　　在JavaScript 1.2版以后，JavaScript也支持正则表达式。 <br/>　　1、replace <br/>　　replace在一个字符串中通过正则表达式查找替换相应的内容。replace并不改变原来的字符串，只是重新生成了一个新的字符串。如果需要执行全局查找或忽略大小写，那么在正则表达式的最后添加g和i。 <br/>例： <br/>&lt;SCRIPT&gt; <br/>re = /apples/gi; <br/>str = &quot;Apples are round, and apples are juicy.&quot;; <br/>newstr=str.replace(re, &quot;oranges&quot;); <br/>document.write(newstr) <br/>&lt;/SCRIPT&gt; <br/>结果是：&quot;oranges are round, and oranges are juicy.&quot; <br/>例： <br/>&lt;SCRIPT&gt; <br/>str = &quot;Twas the night before Xmas...&quot;; <br/>newstr=str.replace(/xmas/i, &quot;Christmas&quot;); <br/>document.write(newstr) <br/>&lt;/SCRIPT&gt; <br/>结果是：&quot;Twas the night before Christmas...&quot; <br/>例： <br/>&lt;SCRIPT&gt; <br/>re = /(&#92;w+)&#92;s(&#92;w+)/;str = &quot;John Smith&quot;; <br/>newstr = str.replace(re, &quot;$2, $1&quot;); <br/>document.write(newstr) <br/>&lt;/SCRIPT&gt; <br/>结果是：&quot;Smith, John&quot;. <br/>　　2、search <br/>search通过正则表达式查找相应的字符串，只是判断有无匹配的字符串。如果查找成功，search返回匹配串的位置，否则返回-1。 <br/>search(regexp) <br/>&lt;SCRIPT&gt; <br/>function testinput(re, str){ <br/>if (str.search(re) != -1) <br/>midstring = &quot; contains &quot;; <br/>else <br/>midstring = &quot; does not contain &quot;; <br/>document.write (str + midstring + re.source); <br/>} <br/>testinput(/^[1-9]/i,&quot;123&quot;) <br/>&lt;/SCRIPT&gt; <br/>　　3、match <br/>　　match方法执行全局查找，查找结果存放在一个数组里。 <br/>例一： <br/>&lt;SCRIPT&gt; <br/>str = &quot;For more information, see Chapter 3.4.5.1&quot;; <br/>re = /(chapter &#92;d+(&#92;.&#92;d)*)/i; <br/>found = str.match(re); <br/>document.write(found); <br/>&lt;/SCRIPT&gt; <br/>显示结果：Chapter 3.4.5.1,Chapter 3.4.5.1,.1 <br/>例二： <br/>&lt;SCRIPT&gt; <br/>str = &quot;abcDdcba&quot;; <br/>newArray = str.match(/d/gi); <br/>document.write(newArray); <br/>&lt;/SCRIPT&gt; <br/>显示结果D, d. <br/><br/>　　四、示例<br/>1 、判断数字的正确性 <br/>&lt;%@ Language=VBScript %&gt; <br/>&lt;script language=&quot;javascript&quot; runat=&quot;server&quot;&gt; <br/>function isNumeric(strNumber) { <br/>return (strNumber.search(/^(-&#124;&#92;+)?&#92;d+(&#92;.&#92;d+)?$/) != -1); <br/>} <br/>function isUnsignedNumeric(strNumber) { <br/>return (strNumber.search(/^&#92;d+(&#92;.&#92;d+)?$/) != -1); <br/>} <br/>function isInteger(strInteger) { <br/>return (strInteger.search(/^(-&#124;&#92;+)?&#92;d+$/) != -1); <br/>} <br/>function isUnsignedInteger(strInteger) { <br/>return (strInteger.search(/^&#92;d+$/) != -1); <br/>} <br/>&lt;/script&gt; <br/>&lt;HTML&gt; <br/>&lt;BODY&gt; <br/>&lt;b&gt;判断数字的正确性&lt;/b&gt; <br/>&lt;% <br/>Dim strTemp <br/>strTemp = CStr(Request.Form(&quot;inputstring&quot;)) <br/>If strTemp = &quot;&quot; Then strTemp = &quot;0&quot; <br/>%&gt; <br/>&lt;TABLE BORDER=&quot;1&quot; CELLPADDING=&quot;4&quot; CELLSPACING=&quot;2&quot;&gt; <br/>&lt;TR&gt; <br/>&lt;TD ALIGN=&quot;right&quot;&gt;&lt;B&gt;原始字符串&lt;/B&gt;&lt;/TD&gt; <br/>&lt;TD&gt;&lt;%= strTemp %&gt;&lt;/TD&gt; <br/>&lt;/TR&gt; <br/>&lt;TR&gt; <br/>&lt;TD ALIGN=&quot;right&quot;&gt;&lt;B&gt;数字&lt;/B&gt;&lt;/TD&gt; <br/>&lt;TD&gt;&lt;%=isNumeric(strTemp)%&gt;&lt;/TD&gt; <br/>&lt;/TR&gt; <br/>&lt;TR&gt; <br/>&lt;TD ALIGN=&quot;right&quot;&gt;&lt;B&gt;非负数字&lt;/B&gt;&lt;/TD&gt; <br/>&lt;TD&gt;&lt;%=isUnsignedNumeric(strTemp)%&gt;&lt;/TD&gt; <br/>&lt;/TR&gt; <br/>&lt;TR&gt; <br/>&lt;TD ALIGN=&quot;right&quot;&gt;&lt;B&gt;整数&lt;/B&gt;&lt;/TD&gt; <br/>&lt;TD&gt;&lt;%=isInteger(strTemp)%&gt;&lt;/TD&gt; <br/>&lt;/TR&gt; <br/>&lt;TR&gt; <br/>&lt;TD ALIGN=&quot;right&quot;&gt;&lt;B&gt;非负整数()&lt;/B&gt;&lt;/TD&gt; <br/>&lt;TD&gt;&lt;%=isUnsignedInteger(strTemp)%&gt;&lt;/TD&gt; <br/>&lt;/TR&gt; <br/>&lt;/TABLE&gt; <br/>&lt;FORM ACTION=&quot;&lt;%=Request.ServerVariables(&quot;SCRIPT_NAME&quot;)%&gt;&quot; METHOD=&quot;post&quot;&gt; <br/>请输入一个数字:&lt;BR&gt; <br/>&lt;INPUT TYPE=&quot;text&quot; NAME=&quot;inputstring&quot; SIZE=&quot;50&quot;&gt;&lt;/INPUT&gt;&lt;BR&gt; <br/>&lt;INPUT TYPE=&quot;submit&quot; Value=&quot;提交&quot;&gt;&lt;/INPUT&gt;&lt;BR&gt; <br/>&lt;/FORM&gt; <br/>&lt;/BODY&gt; <br/>&lt;/HTML&gt; <br/>2、判断Email地址的正确性 <br/>&lt;% <br/>Function isemail(strng) <br/>isemail = false <br/>Dim regEx, Match <br/>Set regEx = New RegExp <br/>regEx.Pattern = &quot;^&#92;w+((-&#92;w+)&#124;(&#92;.&#92;w+))*&#92;@[A-Za-z0-9]+((&#92;.&#124;-)[A-Za-z0-9]+)*&#92;.[A-Za-z0-9]+$&quot; <br/>regEx.IgnoreCase = True <br/>Set Match = regEx.Execute(strng) <br/>if match.count then isemail= true <br/>End Function <br/>%&gt;<br/><br/>　　五、总结 <br/>　　上面我们介绍了正则表达式的基本概念，以及在VBScript和JavaScript中如何使用正则表达式，同时，通过一些实例让大家有了感性的认识。正则表达式的应用范围很广，能为大家解决很多实际中的问题。本文介绍的内容只是一些初步的知识，还有很多语法规则需要大家继续学习，在实践中发现问题，解决问题。 <br/>Tags - <a href="http://www.zhanghaijun.com/tags/asp/" rel="tag">asp</a> , <a href="http://www.zhanghaijun.com/tags/%25E6%25AD%25A3%25E5%2588%2599%25E8%25A1%25A8%25E8%25BE%25BE%25E5%25BC%258F/" rel="tag">正则表达式</a>
]]>
</description>
</item><item>
<link>http://www.zhanghaijun.com/post//#blogcomment</link>
<title><![CDATA[[评论] ASP中正则表达式的应用-2]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.zhanghaijun.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>