MSAccess 中的 VBA 正则表达式 - 查找双引号字符

问题描述 投票:0回答:1

看似简单的问题。我需要使用 SQL 中的 VBA 正则表达式查找表

field1
中的“长文本”
notes
包含以 -”(即连字符和双引号)开头的行的记录。(
field1
使用富文本格式(表和表单字段)。如有必要,我可以删除它,但在我的上下文中,富文本很有用)。 enter image description here

为了让事情变得更容易,我首先尝试匹配包含任何引号字符的字段: 我可以毫无问题地找到包含单引号的字段:

SELECT *
FROM notes
WHERE RegexMatch(field1, ".*'.*")
;

但是双引号失败了

SELECT *
FROM notes
WHERE RegexMatch(field1, ".*"".*")
;

我尝试用另一个引号来转义引号字符。我究竟做错了什么?我还粘贴了我的

RegexMatch()
函数,以防相关。

' ----------------------------------------------------------------------'
' Return True if the given string value matches the given Regex pattern '
' ----------------------------------------------------------------------'
Public Function RegexMatch(value As Variant, pattern As String) As Boolean
    If IsNull(value) Then Exit Function
    ' Using a static, we avoid re-creating the same regex object for every call '
    Static regex As Object
    ' Initialise the Regex object '
    If regex Is Nothing Then
        Set regex = CreateObject("vbscript.regexp")
        With regex
            .Global = True
            .IgnoreCase = True
            .Multiline = True
        End With
    End If
    ' Update the regex pattern if it has changed since last time we were called '
    If regex.pattern <> pattern Then regex.pattern = pattern
    ' Test the value against the pattern '
    RegexMatch = regex.Test(value)
End Function

非常感谢您的帮助

sql regex vba ms-access
1个回答
0
投票

如果列使用富文本格式,则

"
在内部存储为
&quot;

对该列的任何查询都将使用 HTML 源文本,而不是格式化的 HTML。

© www.soinside.com 2019 - 2024. All rights reserved.