共用方式為


Length Property 

Returns the length of a match found in a search string.


object.Length

Arguments

The object argument is always a Match object.

Remarks

The following code illustrates the use of the Length property:

Function RegExpTest(patrn, strng)

   Dim regEx, Match, Matches   ' Create variable.

   Set regEx = New RegExp   ' Create regular expression.

   regEx.Pattern = patrn   ' Set pattern.

   regEx.IgnoreCase = True   ' Set case insensitivity.

   regEx.Global = True   ' Set global applicability.

   Set Matches = regEx.Execute(strng)   ' Execute search.

   For Each Match in Matches   ' Iterate Matches collection.

      RetStr = RetStr & "Match " & I & " found at position "

      RetStr = RetStr & Match.FirstIndex & ". Match Length is "

      RetStr = RetStr & Match.Length 

      RetStr = RetStr & " characters." & vbCRLF

   Next

   RegExpTest = RetStr

End Function

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

Requirements

Version 5

Applies To: Match Object

See Also

Reference

FirstIndex Property
Value Property (VBScript)