Search code examples
regexvbscriptasp-classicregex-negationregexp-like

Regexp Meta Description


When i use this regex on https://regex101.com (<meta[^>]*description[^>]([^<]+)>) its run.

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

but when i use this on my page its not run.

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)

thank you


Solution

  • It's because you have the word "description" inside the content. This causes the first part of the regex (<meta[^>]*description) to skip everything until the last occurrence of "description". Here's the regex that should fix this:

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