I am looking for help creating a regular expression so that I can replace text with an anchor tag. The text is coming from a SQL field (VarChar(max)) and is formatted so:
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua (1954, c. 12; 1968, c. 300; 1994, c. 98)
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua (1998, cc. 553, 568; 2001, c. 300)
In the above text, I need to replace all chapters after 1994 with anchor tags. So for example, 98, 553, 568 and 300 would all be replaced. The following code finds the entire text of 1994, c.98 for example, but I'm not sure how I would replace just the "98" in that text.
Public Shared Function ReplaceChapterTag1(lang As String) As String
Dim l As String = lang
Dim r As Regex = New Regex("199[4-9][/,][/ ][/c]*[/.][/ ][0-9]+(?:\.[0-9]*)?")
Dim applyEvaluator As MatchEvaluator = New MatchEvaluator(AddressOf applyCodeLink)
l = r.Replace(l, applyEvaluator)
Return l
End Function
Private Shared Function applyCodeLink(ByVal m As Match) As String
Dim r As Regex = New Regex("^[0-9]*[\-][0-9]*")
Dim str As String = m.ToString
Dim strReturn As String = ""
Dim match As Match = r.Match(str)
If match.Success Then
strReturn = str
Else
strReturn = "<a href='link?id=" & m.Value & "'>" & m.Value & "</a>"
End If
Return strReturn
End Function
