VBS tutorial: VBScript attribute – length attribute

Time:2021-12-30

Length attribute

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

object.Length

objectParameter is always oneMatchObject.

explain

The following code illustratesLengthProperty usage:

Function regexptest (PATRN, strng) dim regex, match, matches' create variables. Set regex = new regexp 'establish a regular expression. regEx. Pattern = pattern 'sets the pattern. regEx. Ignorecase = true 'sets whether it is case sensitive. regEx. Global = true 'set full availability. Set Matches = regEx. Execute (strng) 'execute the search. For each match in matches' traverse the matches set. Retstr = retstr & "match" & I & "at" retstr = retstr & match Firstindex & ". The matching length is" retstr = retstr & match Length retstr = retstr & "characters."& vbCRLF  Next  RegExpTest = RetStrEnd FunctionMsgBox(RegExpTest("is.",  "IS1 is2 IS3 is4"))