正则表达式元描述

Regexp Meta Description

当我在 https://regex101.com (<meta[^>]*description[^>]([^<]+)>) 上使用此正则表达式时 运行.

Match 1
Full match  265-314 `<meta name="description" content="Whosebug">`
Group 1.    265-314 `<meta name="description" content="Whosebug">`
Group 2.    289-313 ` content="Whosebug"

但是当我在我的页面上使用它时,它不是 运行。

Function GetFirstMatch(PatternToMatch, StringToSearch)
    Set regEx = New RegExp
    regEx.Pattern = PatternToMatch
    regEx.IgnoreCase = True
    regEx.Global = True
    regEx.MultiLine = True
    Set CurrentMatches = regEx.Execute(StringToSearch)

    GetFirstMatch = ""
    If CurrentMatches.Count >= 1 Then
        Set CurrentMatch = CurrentMatches(0)
        If CurrentMatch.SubMatches.Count >= 1 Then
            GetFirstMatch = CurrentMatch.SubMatches(0)
        End If
    End If
    Set regEx = Nothing
End Function

GetFirstMatch("(<meta[^>]*description[^>]([^<]+)>)",sdatai)

谢谢

因为你的内容里面有"description"这个词。这会导致正则表达式的第一部分 (<meta[^>]*description) 跳过所有内容,直到最后一次出现 "description"。这是应该解决这个问题的正则表达式:

(<meta[\s]+name="description"[^>]([^>]+)>)