2009年4月29日星期三

正则匹配非中文字符(ASP版)

项目需要匹配非中文字符。特Google了一把。
%
strTxt=Request.Form("txt")
Response.Write("原输入字符串:"strTxt)
Response.Write("br/")
SetregEx=NewRegExp
regEx.Global=True'设置全局替换
regEx.IgnoreCase=True'设置是否区分大小写
regEx.MultiLine=True
regEx.Pattern="[^\u4e00-\u9fa5]"'设置匹配规则
strResult=regEx.Replace(strTxt,"")'根据规则替换
Response.Write("根据正则规则替换后字符串:"strResult)
Response.Write("br/")
SetMatches=regEx.Execute(strTxt)'根据规则匹配
ForEachMatchinMatches'遍历Matches集合
Response.Write("匹配位置:"Match.FirstIndex"值:"Match.Value)
Response.Write("br/")
Next
retVal=regEx.Test(strTxt)'根据规则测试是否可以匹配到
IfretValThen
Response.Write("找到一个或多个匹配")
Else
Response.Write("未找到匹配")
EndIf
%--EOF--
PostedinASP.TaggedwithASP,正则,非中文字符.By2009/04/23
0Responses
Stayintouchwiththeconversation,subscribetotheRSSfeedforcommentsonthispost.Postacomment
SomeHTMLisOK
Name(required)
Email(required,butnevershared)
Web

没有评论:

发表评论