Multiline 属性

布尔值(True 或 False),用于指定 ^ 和 $ 锚点是否与每行的开始和结束匹配。

Note:

默认值为 False。

属性用法:

语法Object.Multiline = "<True/False>"

示例:

Dim regEx, inputStr, result
Set regEx = CreateObject("VBScript.RegExp")
' Enable multiline mode
regEx.Multiline = True
' Pattern to match the beginning of each line
regEx.Pattern = "^Hello"
regEx.IgnoreCase = True
' Input string with multiple lines
inputStr = "Hello, world!" & vbCrLf & "This is a test." & vbCrLf & "Hello again!"
' Find all lines that start with "Hello"
result = regEx.Test(inputStr)
If result Then
    'Logic Matches at the start of a line.
Else
    'Logic Does not match at the start of any line.
End If

启用 Multiline 时,^ 和 $ 的行为会有所不同,匹配每行的开头和结尾,而不是整个字符串。在上面的示例中,由于 Multiline = True,所以 ^Hello 将匹配 "Hello, world!" 和 "Hello again!",因为两行都以 "Hello" 开头。