Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.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 如何使用带access和VBA的正则表达式匹配字符串_Regex_Vba_Ms Access - Fatal编程技术网

Regex 如何使用带access和VBA的正则表达式匹配字符串

Regex 如何使用带access和VBA的正则表达式匹配字符串,regex,vba,ms-access,Regex,Vba,Ms Access,我有这段代码,但当我使用它时,UrlTest变量返回整个URL,而不是我在正则表达式中定义的捕获组^http:\/\/myanimelist\.net\/animelist\/(.[^\/])(?:\/|)$ 这是我的密码: Private Function UrlTest(strUrl As String) As String 'Do the regEx for get the user in url Dim regEx As New RegExp regEx.Pat

我有这段代码,但当我使用它时,UrlTest变量返回整个URL,而不是我在正则表达式中定义的捕获组<代码>^http:\/\/myanimelist\.net\/animelist\/(.[^\/])(?:\/|)$

这是我的密码:

Private Function UrlTest(strUrl As String) As String
    'Do the regEx for get the user in url
    Dim regEx As New RegExp

    regEx.Pattern = "^http:\/\/myanimelist\.net\/animelist\/(.*[^\/])(?:\/|)$"
    regEx.IgnoreCase = True
    regEx.Global = False

    If regEx.Test(strUrl) Then
        Dim matche As Object
        Set matche = regEx.Execute(strUrl)
        If matche.Count <> 0 Then
            UrlTest = matche(0)
        End If
    Else
        UrlTest = "false"
    End If
End Function
私有函数UrlTest(strUrl作为字符串)作为字符串
'执行正则表达式以获取url中的用户
Dim regEx作为新的RegExp
regEx.Pattern=“^http:\/\/myanimelist\.net\/animelist\/(.[^\/])(?:\/|)$”
regEx.IgnoreCase=True
regEx.Global=False
如果正则表达式测试(strUrl),则
暗匹配对象
Set matche=regEx.Execute(strUrl)
如果匹配,则计数为0
UrlTest=matche(0)
如果结束
其他的
UrlTest=“false”
如果结束
端函数
此函数带有strUrl和
http://myanimelist.net/animelist/example
as value返回相同的值,而不是我想要的:
示例

我不明白!你看,这工作


你应该试试这个。

我必须等五分钟X_xup 1等待Vks,而他在等待:)@Vks
。子匹配(0)
是VBA在Vb.net中捕获组的等价物。组(1)?@JLILIAman可能……不确定……其他所有地方,如python等。
匹配。组(1)
有效。看起来是这样。
UrlTest = matche(0).submatches(0)