非捕获组在完全匹配中被捕获

时间:2017-02-19 02:16:24

标签: regex vbscript

  • 示例字符串:dadasd_37=12abc_dadasd_asdasdasd_asdas_asd

  • 我的正则表达式:(?:_37=)([^_]+)

  • 我想要获得的内容:12abc(任何以37=开头且单词以_结尾的内容。)

但是,完整匹配仍然是_37=12abc

1 个答案:

答案 0 :(得分:3)

通过SubMatches集合访问捕获组匹配项。

<%
Dim regex, matches, match, strSubject, strResult

strSubject = "dadasd_37=12abc_dadasd_asdasdasd_asdas_asd"

set regex = new RegExp
regex.IgnoreCase = True
regex.Pattern = "(?:_37=)([^_]+)"

set matches = regex.Execute(strSubject)

if matches.Count >= 1 then
    set match = matches(0)
    if match.SubMatches.Count >= 1 then
        strResult = match.SubMatches(0)
    else
        strResult = ""
    end If
else
    strResult = ""
end if

response.write "strResult:" & strResult & ""
%>