打印

asp中正则表达式的一些问题。

复制内容到剪贴板
代码:
......
dim re
set re=New RegExp
re.Global=true
re.ignorecase=true
re.multiline=true
......
对正则表达式的这三个属性进行设置,起到什么作用呢?
我知道Global是进行全局搜索,那么何谓全局?和全局相对的又是什么,不全局搜索会发生什么后果?
re.Global=true//全局
re.ignorecase=true//或略大小写
re.multiline=true//多行
全局就是……全局,相对的自然是部分,比如只搜索你指定的次数。
Global 属性
--------------------------------------------------------------------------------

描述
设置或返回一个 Boolean 值,该值指明在整个搜索字符串时模式是全部匹配还是只匹配第一个。
语法
对象.Global [= True | False ]
对象 参数总是 RegExp 对象。如果搜索应用于整个字符串,Global 属性的值为 True,否则其值为 False。默认的设置为 False。


说明
下面的代码说明了 Global 属性的用法(改变赋予 Global 属性的值并观察其效果):
Function RegExpTest(patrn, strng)
  Dim regEx ,match,matches                     ' 建立变量。
  Set regEx = New RegExp                     ' 建立规范表达式。
  regEx.Pattern = patrn                     ' 设置模式。
  regEx.IgnoreCase = True                     ' 设置是否区分字母的大小写。
  regEx.Global = True                            ' 设置全程性质。
set matches= regEx.Execute(strng)              ' 执行搜索。
for each match in matches                             ' 重复匹配集合
RetStr=RetStr &"Match found at position "
RetStr=RetStr&Match.FirstIndex&".Match Value is '"
RetStr=RetStr&Match.Value&"'."&vbCRLF Next
RegExpTest=RetStr
End Function

MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))
--------------------------------------------------------------------------------

IgnoreCase 属性
--------------------------------------------------------------------------------

描述
设置或返回一个Boolean值,指明模式搜索是否区分大小写。
语法
object.IgnoreCase [= True | False ]
Object 参数总是一个 RegExp 对象。如果搜索是区分大小写的,则 IgnoreCase 属性为 False;否则为 True。缺省值为 False。


说明
下面的代码说明了 IgnoreCase 属性的用法(改变赋予 IgnoreCase 属性的值以观察其效果):
Function RegExpTest(patrn, strng)
  Dim regEx,Match,Matches                     ' 建立变量。
  Set regEx = New RegExp                     ' 建立正则表达式。
  regEx.Pattern = patrn                     ' 设置模式。
  regEx.IgnoreCase = True                     ' 设置不区分大小写。
regEx.Global=True                                     ' 设置全局可用性
set matches=regExExecute(string )                     ' 执行搜索。
for each match in matches                             ' 重复匹配集合
RetStr=RetStr &"Match found at position "
RetStr=RetStr&Match.FirstIndex&".Match Value is '"
RetStr=RetStr&Match.Value&"'."&vbCRLF
Next
RegExpTest=RetStr

End Function

MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))
--------------------------------------------------------------------------------