0

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

And 'GIISAssuredController.java':

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

The regex pattern is not working.

I am expecting the output to be is:

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.

This question is related to: Multiline REGEX using VB Script

7
  • 1
    How is it "not working"? What actual results are you seeing? Are there any errors? Commented Apr 14, 2015 at 2:09
  • It doesn't echo anything. I included additional details on the question. Commented Apr 14, 2015 at 2:15
  • you use ForReading before setting its value ? Commented Apr 14, 2015 at 2:28
  • I used ForReading at fileService. Commented Apr 14, 2015 at 2:32
  • 1
    This will never work as it is written. You are reading the input file line by line but you are trying to match a pattern that spawns over two lines. Read the full file and then apply the regexp. Commented Apr 14, 2015 at 7:12

1 Answer 1

2

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 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.