【问题标题】:What is the regex pattern of a string?什么是字符串的正则表达式模式?
【发布时间】:2014-12-10 07:33:02
【问题描述】:

下面的正则表达式模式是什么:

APPLICATION_CONTEXT.getBean("giisParameterFacadeService")

giisParameterFacadeService 的部分是动态的。

我已经试过了:

"APPLICATION_CONTEXT[.]getBean[(]""\s*""[)]"

但它不返回任何东西。

编辑:将其更改为后发生错误:\w*

行:15。字符:8。错误:无效的过程调用或参数。代码。 800A0005

Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set file = objFSO.OpenTextFile("sample.txt" , ForReading)  
Const ForReading = 1

Dim re
Set re = new regexp 
re.Pattern = "APPLICATION_CONTEXT[.]getBean[(]""\w*""[)]"
re.IgnoreCase = True
re.Global = True

Dim line
Do Until file.AtEndOfStream
    line = file.ReadLine
    For Each m In re.Execute(line)
       Wscript.Echo m.Submatches(0)
    Next
Loop

【问题讨论】:

  • \s 匹配空格。你可能想要\w,它匹配A-Za-z0-9_
  • 应用您的建议后发生错误。行:15。字符:8。错误:无效的过程调用或参数。代码。 800A0005
  • Set objFSO = CreateObject("Scripting.FileSystemObject") Set file = objFSO.OpenTextFile("sample.txt" , ForReading) Const ForReading = 1 Dim re Set re = new regexp re.Pattern = "APPLICATION_CONTEXT[.]getBean[(]""\w*""[)]" re.IgnoreCase = True re.Global = True Dim line Do Until file.AtEndOfStream line = file.ReadLine For Each m In re.Execute(line) Wscript.Echo m.Submatches(0) Next Loop

标签: regex string vbscript


【解决方案1】:

其他选项(已测试here):

APPLICATION_CONTEXT\.getBean\(\"(.*)\"\)

【讨论】:

  • 这对我有帮助!它并没有真正回答这个问题,但它成为了我现在正在做的事情的解决方案。谢谢。
【解决方案2】:

试试这个:

APPLICATION_CONTEXT\.getBean[(]""\w*""[)]"

【讨论】:

    猜你喜欢
    • 2015-11-28
    • 1970-01-01
    • 1970-01-01
    • 2019-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多