使用 VB 脚本的多行正则表达式 [英] 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);
模式将包含一个变量:
var = "saveAssured"
reMethod.Pattern = """& var &""[.]equals\(ACTION\).{\n.\w+?.=.\w+?[.](\w+?)\(\w+?\)"
我需要从文本文件中捕获第二个saveAssured".'\n'(新行)似乎不起作用.我用对了吗?我还可以尝试哪些其他步骤?
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?
推荐答案
JavaScript 和 VBScript 没有使点匹配的选项换行符.在这些语言中,您可以使用字符[\s\S]
之类的类来匹配任何字符.这个字符匹配一个是空白字符(包括换行符)的字符字符),或不是空白字符的字符.自从所有字符都是空白或非空白,这个字符类匹配任何字符.
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.
并查看 https://regex101.com/r/kH3aZ4/1
测试适用于 JavaScript,但由于它们具有相同的 Regex 风格,因此该模式也适用于 VBScript.
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]*?\.([^(]*)\("
这篇关于使用 VB 脚本的多行正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!