Sideway BICK BlogSideway BICK BLOG from Sideway

A Sideway to Sideway Home

Link:http://output.to/sideway/default.asp?qno=180500020

Script, Scripting Language, VBScript elements, Server-Side VBScript RegExp Match Object

VBScript RegExp Match Object

RegExp Match Object is a VBScript Object designed for manipulating the matched object returned by Execute Method of RegExp Object. Match Object is the basic unit of matched object per the Pattern Property of RegExp Object. And four Properties are provided for the manipulation of the matched object.

The returns of Execute Property is a collection of submatched objects, that is the SubMatches Collection. Additional Count Property, and Item Property are provided for accessing the Properties of SubMatches Collection directly through dot notation.

  • RegExp Mehtod
    • Execute Method
    • Replace Method
    • Test Method
  • RegExp Property
    • Global Property
    • IgnoreCase Property
    • Pattern Property
    • Execute Method ≡ Matches Collection
      • Count Property
      • Item Property ≡ Match Object
        • FirstIndex Property
        • Length Property
        • Value Property
        • SubMatches Property ≡ SubMatches Collection
          • Count Property
          • Item Property
  • RegExp Collection
    • Execute Method ≡ Matches Collection
      • Item Property ≡ Match Object
        • SubMatches Property ≡ SubMatches Collection

Match Object

last updated 12/11/2017

is to provide access to a regular expression match of a regular expression search.

Syntax

Set rematobjvar=reobjvar.Execute(string).Item(key)

Remarks

  • A Match object can be only created using the Execute method of the RegExp object, which actually returns a collection of Match objects.
  • All Match object properties are read-only.
  • When a regular expression is executed, zero or more Match objects can result.|Each Match object provides access to the string found by the regular expression, the length of the string, and an index to where the match was found.

Requirement

5

Match Properties

last updated 12/11/2017

Four Properties are predefined to manipulate the read-only properties of a Match Object obtained from the Matches Collection returned from the Execute Mothod of RegExp Object.

Syntax

Set rematobjvar=reobjvar.Execute(string).Item(key)
rematobjvar.FirstIndex
rematobjvar.Length
rematobjvar.Value
rematobjvar.SubMatches

Match Collections

last updated 12/11/2017

The output of the SubMatches Property of Match Object is a Collection of SubMatch Objects, namely SubMatches Collection. In other words, Collection of regular expression submatch strings returned by the read-only SubMatches Property of a Match Objcet obtained from the Matches Collection returned from the Execute Mothod of RegExp Object is called SubMatches Collection.

Syntax

Set rematobjvar=reobjvar.Execute(string).Item(key)
Set resubmatcolvar=rematobjvar.SubMatches

Match.SubMarches Property

last updated 12/12/2017

Two Properties are predefined for the returns of SubMarches Property of Match Object, namely, Count Property, and Item Property. Dot notation is used to access the available Property for the SubMatches Collection returned by SubMarches Property of Match Object, for example,
reobjvar.Execute(string).Item(key).SubMatches.propertyname.

Syntax

resubmatcolvar.Count
resubmatcolvar.Item(key)

Examples

Examples of RegExp Object

ASP VbScript Command:
<script runat="server" language="VBScript">
Dim vars,strs,cmda
cmda=array("regexv.Pattern","c","re","strs","regexv.Global","regexv.IgnoreCase")
Dim ucnt,tmp,i:ucnt=UBound(cmda):If var=1 Then:tmp="":Else:tmp="<b>vars</b>":End If:For i=0 to ucnt:tmp=tmp&"<b>"&rmv_ctrl(cmda(i))&", TypeName</b>":Next:Response.Write "Results on Microsoft Windows 8.1 Pro x64, Microsoft-IIS/8.5, VBScript Version 5.8 of page /internet/users/sideblog/default.asp<br />"&"<i>"&tmp&"</i>"
Function dsp_x:Dim tmp_a,tmp_b,i:If varx=0  Then:Execute vars:End If:If var=1 Then:tmp_a="":Else:tmp_a=rmv_ctrl(vars):End If:For i=0 to ucnt:tmp_b=cmd_b(cmda(i)):if i/2=fix(i/2) Then:tmp_b="<b>"&tmp_b&"</b>":End If:tmp_a=tmp_a&tmp_b:Next:Response.Write "<i>"&tmp_a&"</i>":End Function
Function rmv_ctrl(blk_str):Select Case blk_str:Case chr(0):blk_str="NUL":Case chr(1):blk_str="SOH":Case chr(2):blk_str="STX":Case chr(3):blk_str="ETX":Case chr(4):blk_str="EOT":Case chr(5):blk_str="ENQ":Case chr(6):blk_str="ACK":Case chr(7):blk_str="BEL":Case chr(8):blk_str="BS":Case chr(9):blk_str="HT":Case chr(10):blk_str="LF":Case chr(11):blk_str="VT":Case chr(12):blk_str="FF":Case chr(13):blk_str="CR":Case chr(14):blk_str="SO":Case chr(15):blk_str="SI":Case chr(16):blk_str="DLE":Case chr(17):blk_str="DC1":Case chr(18):blk_str="DC2":Case chr(19):blk_str="DC3":Case chr(20):blk_str="DC4":Case chr(21):blk_str="NAK":Case chr(22):blk_str="SYN":Case chr(23):blk_str="ETB":Case chr(24):blk_str="CAN":Case chr(25):blk_str="EM":Case chr(26):blk_str="SUB":Case chr(27):blk_str="ESC":Case chr(28):blk_str="FS":Case chr(29):blk_str="GS":Case chr(30):blk_str="RS":Case chr(31):blk_str="US":Case chr(127):blk_str="DEL":End Select:rmv_ctrl=blk_str:If IsNull(blk_str) OR IsEmpty(Blk_str) OR blk_str="" OR IsNumeric(Blk_str) Then:Else:rmv_ctrl=Replace(Replace(Replace(Replace(Replace(blk_str,"&","&amp;"),"  "," &nbsp;"),"""","&quot;"),"<","&lt;"),">","&gt;"): End If :End Function
Function cmd_b(blk_str):cmd_b="["&cmd_x(blk_str)&"], "&cmd_x("TypeName("&blk_str&")"):End Function
Function cmd_x(blk_str):On Error Resume Next:Dim xans, tmp:xans="":tmp="":execute "xans="&blk_str:If Err.Number <> 0  Then:xans=cmd_x("TypeName("&blk_str&")"):Select Case xans:Case 9::Case Else:xans="error":End Select:End If:If IsArray(xans)=False Then:cmd_x=rmv_ctrl(xans): Else:tmp=lst_arry(xans):cmd_x=trim(tmp):End If:End Function
Function lst_arry(blk_str):Dim tmp,i,q:q="""":tmp="":For i=0 to UBound(blk_str):if VarType(blk_str(i))>1 And VarType(blk_str(i))<6 Then:q="'":End If:tmp=tmp&" "&q&rmv_ctrl(blk_str(i))&q:Next:lst_arry=trim(tmp):End Function

vars="Set regexv = New RegExp: strs="""": re="""": c=""""":dsp_x
vars="regexv.Pattern=""((\w+)@(\w+))\.(\w+)"": strs=""test@testadd.testcom"": re=regexv.Test(strs)":dsp_x
vars="strs=""test@testadd.testcom"": Set re=regexv.Execute(strs): c=re.Count":dsp_x
vars="c=re.item(0)":dsp_x
vars="c=re.item(0).Value":dsp_x
vars="c=re.item(0).FirstIndex":dsp_x
vars="c=re.item(0).Length":dsp_x
vars="Set c=re.item(0).SubMatches":dsp_x
vars="Set re=re.item(0): c=re.SubMatches.count":dsp_x
vars="c=re.SubMatches.item(0)":dsp_x
vars="c=re.SubMatches(1)":dsp_x
vars="c=re.SubMatches.item(2)":dsp_x
vars="c=re.SubMatches(3)":dsp_x
</script>
HTML Web Page In-line Output:
Results on Microsoft Windows 8.1 Pro x64, Microsoft-IIS/8.5, VBScript Version 5.8 of page /internet/users/sideblog/default.asp
varsregexv.Pattern, TypeNamec, TypeNamere, TypeNamestrs, TypeNameregexv.Global, TypeNameregexv.IgnoreCase, TypeNameSet regexv = New RegExp: strs="": re="": c=""[], String[], String[], String[], String[False], Boolean[False], Booleanregexv.Pattern="((\w+)@(\w+))\.(\w+)": strs="test@testadd.testcom": re=regexv.Test(strs)[((\w+)@(\w+))\.(\w+)], String[], String[True], Boolean[test@testadd.testcom], String[False], Boolean[False], Booleanstrs="test@testadd.testcom": Set re=regexv.Execute(strs): c=re.Count[((\w+)@(\w+))\.(\w+)], String[1], Long[IMatchCollection2], IMatchCollection2[test@testadd.testcom], String[False], Boolean[False], Booleanc=re.item(0)[((\w+)@(\w+))\.(\w+)], String[test@testadd.testcom], String[IMatchCollection2], IMatchCollection2[test@testadd.testcom], String[False], Boolean[False], Booleanc=re.item(0).Value[((\w+)@(\w+))\.(\w+)], String[test@testadd.testcom], String[IMatchCollection2], IMatchCollection2[test@testadd.testcom], String[False], Boolean[False], Booleanc=re.item(0).FirstIndex[((\w+)@(\w+))\.(\w+)], String[0], Long[IMatchCollection2], IMatchCollection2[test@testadd.testcom], String[False], Boolean[False], Booleanc=re.item(0).Length[((\w+)@(\w+))\.(\w+)], String[20], Long[IMatchCollection2], IMatchCollection2[test@testadd.testcom], String[False], Boolean[False], BooleanSet c=re.item(0).SubMatches[((\w+)@(\w+))\.(\w+)], String[ISubMatches], ISubMatches[IMatchCollection2], IMatchCollection2[test@testadd.testcom], String[False], Boolean[False], BooleanSet re=re.item(0): c=re.SubMatches.count[((\w+)@(\w+))\.(\w+)], String[4], Long[test@testadd.testcom], IMatch2[test@testadd.testcom], String[False], Boolean[False], Booleanc=re.SubMatches.item(0)[((\w+)@(\w+))\.(\w+)], String[test@testadd], String[test@testadd.testcom], IMatch2[test@testadd.testcom], String[False], Boolean[False], Booleanc=re.SubMatches(1)[((\w+)@(\w+))\.(\w+)], String[test], String[test@testadd.testcom], IMatch2[test@testadd.testcom], String[False], Boolean[False], Booleanc=re.SubMatches.item(2)[((\w+)@(\w+))\.(\w+)], String[testadd], String[test@testadd.testcom], IMatch2[test@testadd.testcom], String[False], Boolean[False], Booleanc=re.SubMatches(3)[((\w+)@(\w+))\.(\w+)], String[testcom], String[test@testadd.testcom], IMatch2[test@testadd.testcom], String[False], Boolean[False], Boolean

Sideway BICK Blog

20/05


Copyright © 2000-2020 Sideway . All rights reserved Disclaimerslast modified on 26 January 2013