且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

正则表达式模式在 VB 脚本中不起作用

更新时间:2023-02-26 12:00:16

如果表达式需要匹配一个生成多行的文本,但是你逐行读取文件并逐行测试,永远不会有匹配.

If the expression needs to match a text that spawns over multiple lines, but you read the file line by line and test line by line, there will never be a match.

Option Explicit

    Const ForReading = 1

Dim code
    code = CreateObject("Scripting.FileSystemObject" _ 
           ).OpenTextFile("GIISAssuredController.java" , ForReading _ 
           ).ReadAll() 

Dim mService

    With new RegExp 
        .Pattern = """\w+?""\.equals\(ACTION\)[\s\S]*?\{[\s\S]*?\.([^(]*)\("
        .IgnoreCase = True
        .Global = True
        For Each mService in .Execute(code)
            WScript.Echo mService.Submatches(0)
        Next 
    End With