正则表达式模式在 VB 脚本中不起作用 [英] Regex pattern not working in VB Script

查看:32
本文介绍了正则表达式模式在 VB 脚本中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 VBS 代码:

I have this VBS code:

Option Explicit

   Dim reMethod, reInterface
    Dim vaction
    Dim fileService
    Dim mService
    Dim lineService
    Dim objFSO

    Const ForReading = 1

    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Set fileService = objFSO.OpenTextFile("GIISAssuredController.java" , ForReading) 

    Set reMethod = new regexp
    reMethod.Pattern = """\w+?""\.equals\(ACTION\)[\s\S]*?\{[\s\S]*?\.([^(]*)\("
    reMethod.IgnoreCase = True
    reMethod.Global = True

    Do Until fileService.AtEndOfStream
        lineService = fileService.ReadLine
        For Each mService In reMethod.Execute(lineService)
           vaction = mService.Submatches(0)
            Set reInterface = new regexp

            Wscript.Echo vaction

        Next
    Loop

和'GISAssuredController.java':

And 'GIISAssuredController.java':

} else if ("hello".equals(ACTION))         {
   Integer assuredNo = giisAssuredService.saveAssured(assured);

正则表达式模式不起作用.

The regex pattern is not working.

我期望输出是:

saveAssured

但相反,它没有回响任何东西.我在这里尝试了正则表达式模式 > https://regex101.com/r/kH3aZ4/1,它正在获取saveAssured"字符串.

But instead, it's not echoing anything. I tried the regex pattern here > https://regex101.com/r/kH3aZ4/1, and it's getting the 'saveAssured' string.

这个问题与:Multiline REGEX using VB Script有关

推荐答案

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

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 

这篇关于正则表达式模式在 VB 脚本中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆