Search code examples
regextextvbscript

Multiline REGEX using VB Script


I have this text file that I need to check:

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

The pattern will include a variable:

var = "saveAssured"
reMethod.Pattern = """& var &""[.]equals\(ACTION\).{\n.\w+?.=.\w+?[.](\w+?)\(\w+?\)"

I need to capture the second 'saveAssured' from the text file. And the '\n' (new line) seems to be not working. Did I used it right? What other steps can I try?


Solution

  • http://www.regular-expressions.info/dot.html

    JavaScript and VBScript do not have an option to make the dot match line break characters. In those languages, you can use a character class such as [\s\S] to match any character. This character matches a character that is either a whitespace character (including line break characters), or a character that is not a whitespace character. Since all characters are either whitespace or non-whitespace, this character class matches any character.

    And have a look at https://regex101.com/r/kH3aZ4/1
    Test is for JavaScript but since they have the same Regex flavor, that pattern will also work with VBScript.

    Dim reMethod
    Set reMethod = New RegExp
        reMethod.IgnoreCase = True
        reMethod.Pattern = """saveAssured""\.equals\(ACTION\)[\s\S]*?\{[\s\S]*?\.([^(]*)\("