Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 查看VBA的正则表达式?_Regex_Vba_Lookbehind_Negative Lookbehind - Fatal编程技术网

Regex 查看VBA的正则表达式?

Regex 查看VBA的正则表达式?,regex,vba,lookbehind,negative-lookbehind,Regex,Vba,Lookbehind,Negative Lookbehind,在VBA正则表达式中,有没有一种方法可以进行负查找和正查找 如果字符串以“A”开头,我希望不匹配,因此我当前正在模式开头执行^A,然后删除匹配的第一个字符(0)。显然不是最好的方法 我使用的是regExp对象。将^A放在未捕获的组中,然后使用Match对象的SubMatches属性来获取匹配的值如何?VBA提供正面和负面的lookahead,但不一致地不提供lookahead 我见过的将正则表达式与VBA结合使用的最好例子是Patrick Matthews [使用执行而不是替换更新了示例] 虽然

在VBA正则表达式中,有没有一种方法可以进行负查找和正查找

如果字符串以“A”开头,我希望不匹配,因此我当前正在模式开头执行^A,然后删除匹配的第一个字符(0)。显然不是最好的方法


我使用的是regExp对象。

将^A放在未捕获的组中,然后使用Match对象的SubMatches属性来获取匹配的值如何?

VBA提供正面和负面的lookahead,但不一致地不提供lookahead

我见过的将正则表达式与VBA结合使用的最好例子是Patrick Matthews

[使用
执行
而不是
替换更新了示例]

虽然我不完全清楚您的用法,但您可以将这样的函数用于

  • 跳过任何以A开头的单词
  • 对于所有不以a开头的单词,它返回从第二个字符开始的所有内容(使用子匹配-内部的模式
    是子匹配1-

    Sub TestString()
    MsgBox ReducedText("cfat dcat")
    MsgBox ReducedText("Sat all over the hat again")
    End Sub
    
    
    Function ReducedText(strIn As String) As String
    Dim objRegex As Object
    Dim objRegMC As Object
    Dim objRegM As Object
    Dim strOut As String
    Set objRegex = CreateObject("vbscript.regexp")
    With objRegex
      .IgnoreCase = True
      'not needed if matching the whole string
      .Global = True
      .Pattern = "\b[^a\s]([a-z]+)"
      If .test(strIn) Then
          Set objRegMC = .Execute(strIn)
          For Each objRegM In objRegMC
            strOut = strOut & objRegM.submatches(0) & vbNewLine
          Next
          ReducedText = strOut
      Else
        ReducedText = "Starts with A"
      End If
    End With
    End Function
    

我假设您正在使用对象?听起来很有趣。如何使用子匹配?