I'm trying to search a regular expression pattern and, if it matches, find whether the value of that pattern exists inside any one of tags of the form <sec id="secXYZ"> in a file. If it does, then it goes to the next search match and if it doesn't match, I want to replace it with result1 as described in the code. I think it can be done with the "MatchEvaluator" function, but I can't figure out how to apply it.

I'm new to VB.NET (and programming in general) and really don't know what to do. This is what I've tried so far:

Code:
Dim pattern As String="(?<=rid=\"sec)(\\d+)(?=\">)"
Dim r As Regex = New Regex(pattern)
Dim m As Match = r.Match(input)
If (m.Success) Then
    Dim x As String=" id=""sec"+ pattern +""""
    Dim r2 As Regex = New Regex(x)
    Dim m2 As Match = r2.Match(input)
    If (m2.Success) Then
        Dim tgPat AsString="<xref ref-type="section" rid=""sec + pattern +"">(\w+) (\d+)</xref>"
        Dim tgRep As String= "$1 $2"
        Dim tgReg As New Regex(tgPat)
        Dim result1 As String = tgReg.Replace(input, tgRep)
    Else
    EndIf
EndIf
Next